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 / Combining GroupBy And ...
Power Apps
Unanswered

Combining GroupBy And Sort

(1) ShareShare
ReportReport
Posted on by 2,914

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

 

Thanks

Paul

Categories:
I have the same question (0)
  • Leo09 Profile Picture
    212 on at

    Maybe you need to seperate the steps. You need to first groupby the gallery and then use another place to sort the gallery.

  • PaulD1 Profile Picture
    2,914 on at

    Well, something seems to have changed because now my results do sort (yay!). This is using the SortBy syntax used in the original post.

     

    But... as I scroll through the returned results in a gallery they consistently cause the app to crash (boo!)

  • Verified answer
    hpkeong Profile Picture
    2,944 on at

    Hi @PaulD1

     

    Normally, GroupBy will be used in conjunction with ClearCollect so that the results will be collected into Temporary table and this table is referred to Gallery,Items = TableCollected.

     

    In this case, you shall be getting smooth results.

     

    Please see this good tutorial and definitely helps.

    https://powerapps.microsoft.com/en-us/tutorials/function-groupby/

     

    TQ

  • PaulD1 Profile Picture
    2,914 on at

    Thanks @hpkeong

     

    For various reasons, I have ended up using a Collection in the end. Still getting the occasional crash in the designer when I am dealing with 'large' amounts of test data, but seems to be OK in the player with more realistic work-loads, so fingers crossed, all good for now 🙂 

  • satya Profile Picture
    40 on at

    Hi Paul,

     

    i have a sharepoint list which is having morethan 3000 records, in that list a column having yes/no field. i have created a gallery which shows based on the auditor(people picer) i am using the below query in main gallery but i am not able to filter. i need sorting based on auditor field.

    ClearCollect(data,GroupBy(SortByColumns(Filter(Begehungen,,Abgeschlossen=0),AddColumns(Begehungen,"DisplayName",Auditor.DisplayName),If(SortDescending1,Descending,Ascending)),"DisplayName","BegehungenGroup"))

  • AyoubH Profile Picture
    4 on at

    So, I am trying to group the row by value to give something like that, but I can not get it done. If someone can assist/help it would be very appreciated please and thanks

     

    Capture.PNG

  • PaulD1 Profile Picture
    2,914 on at

    Sorry, very late reply, but in case it still helps...

    In a flexible height vertical gallery, set the Items as a GroupBy of the 'Unite de travail' and assign the GroupColumnName as something like 'UniteDetail'

    Add a label to the gallery and set the text property it to ThisItem.'Unite de travail' and set AutoHeight to true.

    Add a normal vertical gallery inside the existing gallery to the right of 'Unite de travail' label. Set it's Items property to ThisItem.'UniteDetail'. You can now add the labels for 'Statut du poste', etc.

    You'll need to ensure that each instance of your inner gallery is tall enough to show the data. Figure out the height of the template for the inner gallery and set the inner gallery height to CountRows(ThisItem.'UniteDetail' * template_height) - you may also need to account for any template padding. Now the inner gallery should grow vertically to fit your data and this will make the template of the outer gallery grow to accommodate it.

  • Community Power Platform Member Profile Picture
    on at

    Hi @PaulD1 ,

     

    Saw your Youtube video on Groupby collapse and uncollapsed Gallery.

     

    Could you share your solution on how you manage to sort your GroupBy?

     

     

  • PaulD1 Profile Picture
    2,914 on at

    @Anonymous 

    If you need to sort the Parent - in your main gallery you can set the items property to:

    Sort(GroupBy(MyTable,MyGroupField1,GroupedFields), MyGroupField1)

     

    If you want to sort the Child elements, in your Subgallery set the Items property to Sort(ThisItem.GroupedFields,FieldToSortBy).

     

    Hope that makes sense.

  • Community Power Platform Member Profile Picture
    on at

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

     

     

     

     

     

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

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 333 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard