web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Iterating over a list ...
Power Apps
Unanswered

Iterating over a list for comparing it with another list

(0) ShareShare
ReportReport
Posted on by

Hello,

i have two lists A and B. I need to check if all elements of A are present in B, and remove the elements that are not present in B.

 

In normal programming i would use a while or for loop to iterate over each item and check if it exists in list B, how should i do in power apps???

 

thank you so much

Categories:
I have the same question (0)
  • v-qiaqi@microsoft.com Profile Picture
    on at

    Hi @Antonioclk,

    Could you please tell me if there is primary key between listA and listB?

     

    If there is a column like ID existing in listA and listB, you could add a Gallery and set its Items property as:

    Filter(listA,ID in listB.ID)

    This will display elements of A are present in B.

     

    To remove the elements are not present in B, you could add a butto  and set OnSelect:

    RemoveIf(ListA,!(ID in ListB.ID))
  • Antonioclk Profile Picture
    on at

    thanks for the quick answer... actually there is no ID.
    List A has only a Value column with elements like "soccer, cooking, reading".

    List B has several columns, and the one that interest me is "Skill" column, which have elements like "soccer, cooking" but has less skills than the ones in list A.
    I need to remove the elements of A that are not present in B. 

     

    Basically it's a migration from an old db, where the list of skills had more elements, to a newer list where there are less elements. I want to remove entries that are not in the list anymore

    in power apps i get lost on how to do such operations that normally would require a for or while loop 😄

  • v-qiaqi@microsoft.com Profile Picture
    on at

    Hi @Antonioclk,

    In Power Apps, this Filter() function does loop through both lists, however, if there is a primary key, it is hard to iterate.

     

    The reason why we need a id column is that we need a unique column to compare with the one in listB so that we could capture the record easily.

     

    There is a function ForAll() to loop through the records in a table.

    ForAll function in Power Apps - Power Platform | Microsoft Learn

  • Antonioclk Profile Picture
    on at

    I basically have an old list of skills on the db. The new dropdown, has fewer skills, so i want to remove from the db all the items that are not in the dropdown anymore. 

     

    I just cleaned the code to simplify... i now have

    • CollectionA (the old list from the db) with only the Value column and inside there's "soccer, cooking, reading, swimming, programming"
    • CollectionB (the correct list that is used as reference to compare and remove) with only the Skill column and inside there's "soccer, swimming, cooking, yoga"

    i should have a new list (or fix the CollectionA) that would show just "soccer, cooking, swimming".

     

    I placed the two lists insde 2 tables and they are shown correctly,

    then i tried to make a new table with this code, but it doesn't work. it shows an error on the tmpCurrentSkillsList.Value, why?

     

     

    Filter(collectionA, Value in CollectionB.Skill)

     

     

     

  • Antonioclk Profile Picture
    on at

    i changed syntax and used

    Filter(collectionA, Value in CollectionB)

    and showed no errors, but still it's not correct.

     

    Screenshot 2023-07-19 123149.png

    as you can see from the picture, the first list, has more elements that should be added in the filter, for instance Power App or Power Automate... but the filtered list only shows one element

  • Verified answer
    v-qiaqi@microsoft.com Profile Picture
    on at

    Hi @Antonioclk,

    I am back to my office now, a new day.😂

    I will test it later and responde here to update...

     

    UPDATE

    To check if all the records from ListA existing in ListB, I have a simple demo for your reference.

    1). colA has a column named Title, colB has a column named Title.

    2). Only1,2,5 from colA exist in colB, so based on your need, you just want to list 1,2,5 in the Gallery and remove 3,4,Tues from colA, right?

    vqiaqimsft_0-1689827004041.png

    3). To delete the elements not existing in colB, you just need to use the RemoveIf():

    RemoveIf(colA,!(Title in colB.Title))

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard