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.

Advocate I
Advocate I

Thanks @PaulD1 

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


Demo Extravaganza Winner Announcement

Please join us on Wednesday, July 21st at 8a PDT. We will be announcing the Winners of the Demo Extravaganza!

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Top Kudoed Authors
Users online (4,342)