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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Unanswered

ForAll collection

(0) ShareShare
ReportReport
Posted on by 792

Hi Community 

 

Im trying to get back into power apps, I have this code I'm using to try and increase the amount I can obtain in a collection which works to a degree, however I'm getting duplicates for the values can anyone see what I'm doing wrong? 
Many thanks in advance

Clear(collection);
ForAll(
["value1", "value2", "value3", "value4", "value5"],
Collect(collection,
Filter(SOURCE, 'COLUMN NAME'=Value),
Filter(SortByColumns(collection,"ID",SortOrder.Descending),ID>0))
);

Categories:
I have the same question (0)
  • Hassan_SZ_365 Profile Picture
    542 on at

    Hi @Kmayes ,

    Your code may generate duplicates due to missing distinct values in the Collect function. Try modifying your code like this: 

     

    Clear(collection);
    ForAll(
     ["value1", "value2", "value3", "value4", "value5"],
     Collect(
     collection,
     Distinct(Filter(SOURCE, 'COLUMN NAME' = Value)),
     SortByColumns(collection, "ID", SortOrder.Descending),
     ID > 0
     )
    );

     

    Adding Distinct ensures unique values are collected, potentially resolving the duplicate issue. Test it in your Power Apps to see if it addresses the problem.

    Best Regards,
    Hassan Raza

     
     
  • Kmayes Profile Picture
    792 on at

    Hi @Hassan_SZ_365 

    Not sure why but the last part has red underline due to invalid arguments?

     

  • CarlosFigueira Profile Picture
    Microsoft Employee on at

    Hi @Kmayes your expression seems strange in a way that you are in your collection you are adding both the items from the source into the collection, as well as the items from the collection itself. So in some items in the ForAll loop you will be adding back to the collections items that have already been collected. That doesn't sound right, and will cause duplicates:

    Clear(collection);
    ForAll(
     ["value1", "value2", "value3", "value4", "value5"],
     Collect(
     collection,
     Filter(SOURCE, 'COLUMN NAME' = Value),
     Filter(
     SortByColumns(
     collection, // Do you want to add the items from 'collection' into 'collection'?
     "ID",
     SortOrder.Descending),
     ID > 0
     )
     )
    );

    If you only want to add items to the collection from SOURCE that have the column name equal to the value from ForAll and the ID greater than 0, then you can use something like the expression below:

    Clear(collection);
    ForAll(
     ["value1", "value2", "value3", "value4", "value5"],
     Collect(
     collection,
     Filter(
     SOURCE,
     And(
     'COLUMN NAME' = Value,
     ID > 0
     )
     )
     )
    );

    Hope this helps!

  • Kmayes Profile Picture
    792 on at

    Hi @CarlosFigueira Yes, I only require adding items to the collection from the source. However, the code used above throws back a delegation error and won't return any items.?

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 429 Most Valuable Professional

#2
11manish Profile Picture

11manish 191 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 122 Super User 2026 Season 2

Last 30 days Overall leaderboard