Showing results for 
Search instead for 
Did you mean: 
Super User
Super User

Combining GroupBy And Sort

I'm using a GroupBy in my datasource for a Gallery-SubGallery set up. I'm taking data from an OrderDetails table which includes an OrderHeaderID which is the field I am grouping on.


GroupBy(Filter('[Order].[OrderDetail]',OrderDetailTimeInt >= varTodayInt)  ,"OrderHeaderID","GrpOrderByHeader")

By befault, the records appear to be shown in the Gallery in Ascending order (of the OrderHeaderID). I would prefer they be shown in descending order. I have tried adding a Sort to the formula as follows:

SortByColumns(GroupBy(Filter('[Order].[OrderDetail]',OrderDetailTimeInt >= varTodayInt)  ,"OrderHeaderID","GrpOrderByHeader"),"OrderHeaderID",Descending)

Unfortunately, this not only appears to have a considerable hit on performance but doesn't actually perform a sort, instead mixing up the records so I actually get multiple copies of the same OrderHeaderID with only some of the related records appearing under each.


Is there a way to sort the result set of a GroupBy? What I really want to do is lookup the OrderHeaderDate for each OrderHeaderID and sort by that, but as OrderHeader records have an auto-incrementing ID, sorting by the ID would be sufficient for now...





Hi @PaulD1 ,


Thanks for the response! 🙂 I am using Sub Gallery same with you toturial.


Can my Groupby sorted by ascending or descending on (eg OrderID)?






Sorts are Ascending by default, but just specify Descending as an additional parameter - e.g.

Helpful resources

PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

Power Apps Community Call

Monthly Power Apps Community Call

Did you miss the call?? Check out the Power Apps Community Call here!


Experience what’s next for Power Apps

See the latest Power Apps innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Power Platform ISV STudio

Power Platform ISV Studio

ISV Studio is the go-to Power Platform destination for ISV’s to monitor & manage applications post-AppSource publish.

Top Solution Authors
Top Kudoed Authors
Users online (46,031)