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 / Sort Gallery by CountR...
Power Apps
Unanswered

Sort Gallery by CountRows of Nested Gallery

(0) ShareShare
ReportReport
Posted on by 77

Hi dear community,

I have a Gallery with a Nested Gallery.

The Gallery has Items: "Sort(GroupBy(Search('Inventory',TextInput5_1.Text, "Category"),"Category", "DATA"),Category,Ascending)"

I have a button in the Gallery with Text: "ThisItem.Category & " " & CountRows(Gallery11.AllItems)" (Gallery11 is the nested gallery).

This gives me a result of:

marney_0-1650714492714.png

As you can see, it is giving me a count of the records in the Nested Gallery (great!).

All I want to acheive now is to sort that gallery by the CountRows of the nested gallery so in the above pic, IS CORE SUPPORT would be at the top (because it has a count of 4) etc.

 

Thanks so much as always!

 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    156,340 Most Valuable Professional on at

    Hi @marney ,

    This should do it.

    Sort(
     AddColumns(
     GroupBy(
     Search(
     'Inventory',
     TextInput5_1.Text, 
     "Category"
     ),
     "Category", 
     "DATA"
     ),
    	 "ItemCount"
     CountRows(DATA)
     ),
     ItemCount,
     Descending
    )

     

    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.

    Visit my blog Practical Power Apps

  • marney Profile Picture
    77 on at

    Hi Warren!

    Thats the second time you've helped me and helped multiple others; I am eternally grateful...thank you!
    That worked perfectly...I was thinking that by sorting the gallery in descending, when I perform a search using the text box, the result would make it to the top of the gallery; for example, I enter "web" for the seach and we can see there is only one result under EDA but it hasn't "climbed" up to the top of the gallery. 

    I know this is a difficult one but if you have any thoughts that you could share with me, I will be indebted to you once again!

    marney_0-1650752464079.png

    Thanks again Warren,

    Marney

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

    Hi @marney ,

    I am a little confused as your search should only display only matching items if it is working - or are you wanting a different sort when searching ? Also if you are only searching one element, I tend to do this

    Sort(
     AddColumns(
     GroupBy(
     Filter(
     'Inventory',
     Len(TextInput5_1.Text) = 0 || TextInput5_1.Text in Category
     ),
     "Category", 
     "DATA"
     ),
    	 "ItemCount"
     CountRows(DATA)
     ),
     ItemCount,
     Descending
    )

     

    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.

    Visit my blog Practical Power Apps

  • marney Profile Picture
    77 on at

    hi again Warren,

    The search is being performed on the Nested Gallery item (ThisItem.Choices) which works great. 

    The CountRows is calculating how many records for each Category.

    From the pic, you can see that the search  "Web" is finding one entry under EDA:

    marney_1-1650786506661.png

     

    I'm trying to get that EDA up to the top of the gallery, so the user doesn't have to scroll through the gallery to find the Category that contains the search result.

    My thinking was that by sorting the Gallery on CountRows, EDA would have made its way to the top as it now has "1" where all the others have "0".

    Thanks again!

    marney

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

    Hi @marney ,

    Please excuse my confusion, but I having difficultly visualising what you are doing here. What is the current Items (in Text please) of the gallery that is producing those results ?

  • marney Profile Picture
    77 on at

    hi again Warren!

    Thank you mate for your continued assistance.

    Of course; for the main Gallery, items are:

     

    Sort(
    AddColumns(
    GroupBy(
    Filter(
    'Inventory',
    Len(TextInput5_1.Text) = 0 || TextInput5_1.Text in Category),"Category", "DATA"),"ItemCount", CountRows(DATA)
    ),
    ItemCount,
    Descending
    )

     

    For the Nested Gallery (which holds the records):

    Filter(' Inventory',Category=ThisItem.Category)

     

    The blue button that is also inside the Nested Gallery (Gallery11) has a Text of:

    ThisItem.Category & " " & CountRows(Gallery11.AllItems)

     

    Cheers!

     

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

    Hi @marney ,

    The Items of the nested gallery should be

    ThisItem.Data

    That is the only reason to nest a gallery - when the Items are a sub-set of the Parent gallery item that it is nested in. I assumed that you wanted the count in the Parent gallery with this code

    Sort(
     AddColumns(
     GroupBy(
     Filter(
     'Inventory',
     Len(TextInput5_1.Text) = 0 || 
     TextInput5_1.Text in Category
     ),
     "Category", 
     "DATA"
     ),
     "ItemCount", 
     CountRows(DATA)
     ),
     ItemCount,
     Descending
    )

    The blue buttons should be

    ThisItem.Category & " " & CountRows(ThisItem.Data)

     

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

    Hi @marney ,

    Just checking if you got the result you were looking for on this thread. Happy to help further if not.

    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.

    Visit my blog Practical Power Apps

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 392 Most Valuable Professional

#2
11manish Profile Picture

11manish 181 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 112 Super User 2026 Season 2

Last 30 days Overall leaderboard