web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Sorting subgallery und...
Power Apps
Unanswered

Sorting subgallery under the main gallery

(0) ShareShare
ReportReport
Posted on by 35

I'm working on a voting app, and I created the results screen based on this video by Reza Dorrani 

My galleries look like this:

macsevet_0-1693327129804.png

 

I want to sort the gallery items in descending order based on the number of nominations, but I can't figure out how to do it.

The code for the Number of nominations (NumberOfNominations_sum) Text property: 

 

CountRows(Gallery7.AllItems)

 

And the Items property of the main gallery:

 

GroupBy(
 AddColumns(
 StarAwards_DeviceOperations_Nominees, "NomineeText", Nominee.DisplayName
 ), 
 "NomineeText", 
 "Data"
 )

 

  Not sure how to use the Filter and Sort functions in this case.

Thanks in advance for any suggestion!

Categories:
  • WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at

    Hi @macsevet ,

    The structure would be something like this

    GroupBy(
     AddColumns(
     Sort(
     Filter(
     StarAwards_DeviceOperations_Nominees,
     YourFilterHere
     ),
     YourSortHere
     ),
     "NomineeText", 
     Nominee.DisplayName
     ), 
     "NomineeText", 
     "Data"
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • macsevet Profile Picture
    35 on at

    Hi @WarrenBelz ,

    Thank you for the quick reply!

    I'm sorry, I might be a bit lost in here. I only added now the Sort function as below, but I got 8 errors about it giving circular references:

    GroupBy(
     AddColumns(
     Sort(
     StarAwards_DeviceOperations_Nominees,
     CountRows(SubGallery_NominationDetails.AllItems),
     SortOrder.Descending
     ),
     "NomineeText", 
     Nominee.DisplayName
     ), 
     "NomineeText", 
     "Data"
    )

    And this is the nested gallery setup:

    macsevet_0-1693406978518.png

    Can you please check what am I doing wrong?

    Many thanks!

     

  • AndrewR1 Profile Picture
    1,572 Moderator on at

    This won’t work sorry 

     

  • macsevet Profile Picture
    35 on at

    Hi @AndrewR1 ,

    Thanks for the help!

    Although with your code I got this error: "The specified column 'CountRows(Data)' does not exist."

    I modified that line as below, but now this error pops up: "Invalid argument type (Number). Expecting a Text value instead."

     

    SortByColumns(
     GroupBy(
     AddColumns(
     StarAwards_DeviceOperations_Nominees,
     "NomineeText",
     Nominee.DisplayName
     ),
     "NomineeText",
     "Data"
     ),
     CountRows(SubGallery_NominationDetails.AllItems),
     SortOrder.Descending
    )

    Could you please advise what to modify? 🙂

    Thanks!

     

  • WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at

    @macsevet ,

    You cannot Sort by CountRows - you would have to do this - I am assuming this is not the Items of the SubGallery mentioned.

    GroupBy(
     Sort(
     AddColumns(
     StarAwards_DeviceOperations_Nominees,
     "Rows",
     CountRows(SubGallery_NominationDetails.AllItems),
     "NomineeText", 
     Nominee.DisplayName
     ), 
     Rows,
     SortOrder.Descending
     ),
     "NomineeText", 
     "Data"
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at

    @macsevet ,

    You cannot sort a gallery by itself (hence the circular reference)

  • macsevet Profile Picture
    35 on at

    @WarrenBelz, I was trying to add this code you sent the last time to the Items property of 'MainGallery_Nominees', but it also creates circular references:

    macsevet_0-1693485339687.png

    If this approach is not possible at all, do you have maybe any tips for another solution?

  • WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at

    @macsevet ,

    Sorry, not that I can think of if you are trying to sort a gallery by the row count of a sub gallery that has direct relationship with the contents of the main item.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard