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 a Gallery base...
Power Apps
Answered

Sorting a Gallery based off of a countRows function

(0) ShareShare
ReportReport
Posted on by 17

I have a gallery that shows the count of my items in a sharepoint list, based off of a radio button selection. However, it is only able to sort based off of employee names. I want to have the highest counts at the top. Is there a way to get that data from the count rows pulled into a table that I can sort? I have been trying the AddColumns function but am not familiar with it. 

 

Stikelee_0-1715891839106.png

Here is the Gallery Code -

Sort(GroupBy(Filter(AisleQualityCollection,StartsWith('Slot Number',Radio1.Selected.Title)),Title,Employee),Title,SortOrder.Ascending)

 

Here is the Count formula - 

CountRows(Filter(AisleQualityCollection,Title=ThisItem.Title,Left('Slot Number',1)= Radio1.Selected.Title,'Reviewed?'="Yes"&Title<>"A1 -- Needs Researched"))

 

Thanks in advance!

Categories:
I have the same question (0)
  • Verified answer
    Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @Stikelee - I think the below is what you're trying to do. Note that "Shaping" or "Transform" functions like AddColumns and GroupBy are not delegable with any data source.

     

     

    Sort(
     AddColumns(
     GroupBy(
     Filter(
     AisleQualityCollection,
     StartsWith(
     'Slot Number',
     Radio1.Selected.Title
     )
     ),
     Title,
     GroupedItems
     ),
     CountItems,
     CountRows(
     Filter(
     GroupedItems,
     Left('Slot Number', 1)= Radio1.Selected.Title,
     'Reviewed?'= "Yes",
    		Title <> "A1 -- Needs Researched"
     )
     )
     ),
     CountItems,
     SortOrder.Descending
    )

     

    Same result as above but easier to read:

     

    With(
     {
     _prefiltered_data: Filter(
     AisleQualityCollection,
     StartsWith(
     'Slot Number',
     Radio1.Selected.Title
     )
     )
     },
     Sort(
     AddColumns(
     GroupBy(
     _prefiltered_data,
     Title,
     GroupedItems
     ),
     CountItems,
     CountRows(
     Filter(
     GroupedItems,
     Left('Slot Number', 1)= Radio1.Selected.Title,
     'Reviewed?'= "Yes",
    		 Title <> "A1 -- Needs Researched"
     )
     )
     ),
     CountItems,
     SortOrder.Descending
     )
    )
  • Stikelee Profile Picture
    17 on at

    @Amik I tried that in the items section of the gallery and it definitely changed the order. 

     

    This is what I am getting from the above:

    Stikelee_0-1715953637782.png

     

  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @Stikelee - do you have a question?

  • Stikelee Profile Picture
    17 on at

    @Amik Yes, in the second image I show on this page, it has the counts but they are not in a descending or ascending order after using the code that you gave. How can I fix that?

  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @Stikelee - please share the code you have used (in text) and a screenshot of the output table. The screenshots you have shared do not tell me anything.

  • Stikelee Profile Picture
    17 on at

    @Amik sorry about the confusions. I tried the code that you gave above. Both instances gave me the same result. The code and output are shown below:

     

    Sort(
    AddColumns(
    GroupBy(
    Filter(
    AisleQualityCollection,
    StartsWith(
    'Slot Number',
    Radio1.Selected.Title
    )
    ),
    Title,
    GroupedItems
    ),
    CountItems,
    CountRows(
    Filter(
    GroupedItems,
    Left('Slot Number', 1)= Radio1.Selected.Title,
    'Reviewed?'= "Yes",
    Title <> "A1 -- Needs Researched"
    )
    )
    ),
    CountItems,
    SortOrder.Descending
    )

    Stikelee_0-1716324495526.png

     

  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @Stikelee - I want to look at the table returned from the formula.

     

    On the Formula Bar, double click the "Sort" function at the top, and click "Table" (it might take a few seconds to appear), then share a screenshot of the output. Example below;

     

    Amik_0-1716325448699.png

     

  • Stikelee Profile Picture
    17 on at

    Stikelee_0-1716325648929.png

    It is returning this and the Title. The title has names so I did not want to share that. 

     

  • Stikelee Profile Picture
    17 on at

    @Amik I also see it returning a lot of zeros towards the bottom of the count column. Not sure if that helps or not. 

  • Ami K Profile Picture
    15,687 Super User 2024 Season 1 on at

    @Stikelee - the fact that the preview window is correctly sorting the count of items in descending / highest to lowest order, that should give you an indication that the formula is correct, but whatever you're doing in the Gallery is not...

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Vish WR Profile Picture

Vish WR 1,027

#2
Valantis Profile Picture

Valantis 644

#3
11manish Profile Picture

11manish 626

Last 30 days Overall leaderboard