cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Advocate IV
Advocate IV

Order collection after filter?

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

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Microsoft
Microsoft

Re: Order collection after filter?

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

 

View solution in original post

3 REPLIES 3
Highlighted
Microsoft
Microsoft

Re: Order collection after filter?

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).

Highlighted
Advocate IV
Advocate IV

Re: Order collection after filter?

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

 

Highlighted
Microsoft
Microsoft

Re: Order collection after filter?

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

 

View solution in original post

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

August 2020 CYST Challenge

Check out the winners of the recent 'Can You Solve These?' community challenge!

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Users online (3,809)