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 / Order collection after...
Power Apps
Answered

Order collection after filter?

(0) ShareShare
ReportReport
Posted on by 35

Hello,

 

Can I be sure that the order of the filtered elements of collection Filter(...) will be the same as when it was created ClearCollect(SortByColumns(...))?

Regards,

MarcelLee

Categories:
I have the same question (0)
  • dinusc Profile Picture
    Microsoft Employee on at

    Hello @MarcelLee,

    Can you please clarify the intended behavior? The formula from your message does not seem to be correct.

    Generally, when you're pulling a sorted list which contains identical items then the order of those identical items is not guaranteed. You will have to also sort by other columns. Example:

    If your formula is ClearCollect(ColName ,SortByColumns( MyTable, "aaa", Ascending)

    ... and MyTable contains identical values in the "aaa" column then the order of those values in the ColName will not be guaranteed. In order to get the expected order, you will also have to sort by another column (ID or DateCreated for example).

  • MarcelLee Profile Picture
    35 on at

    Hello @dinusc

     

    Of course I make mistake in my quasi formulas.

     

    During the application startup I caching the contents of the SQL table in the collection using the function:

    ClearCollect(
     collectionName; 
     SortByColumns(
     sqlTableName; 
     "columnA"; SortOrder.Ascending; 
     "columnB"; SortOrder.Ascending; 
     "columnC"; SortOrder.Ascending; 
     "columnD"; SortOrder.Ascending; 
     "columnE"; SortOrder.Ascending; 
     "columnF"; SortOrder.Ascending; 
     "columnID"; SortOrder.Ascending
     )
    )

    Later, depending on the context, I filter this collection using the fliter function.

    Filter(
     collectionName; 
     columnD = x 
    )

    My question is:

    Will I be 100% sure of order filtered elements of collection if I sort (in deterministic way) elements of collection when I create?


    The sort function is fully deterministic because the last criterion is the columnID (primary key) in the SQL table.

     

    Regards,

    MarcelLee

     

  • Verified answer
    dinusc Profile Picture
    Microsoft Employee on at

    Yes. The sorting order will be consistent with the formula provided.

    BTW, the consistency will most likely be guaranteed by the SQL Server, not PowerApps, because the SortByColumns  function is delegable which means it will be run on the server *not on the PowerApps client). Please see this for more details: https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/delegation-list

     

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 765 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 272

Last 30 days Overall leaderboard