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 by t...
Power Apps
Answered

Sorting a Gallery by the Calculated Result of a Label From a Different Source Than The Gallery

(0) ShareShare
ReportReport
Posted on by

This is likely a CRAZY question, but in the interest of time and having looked at lots of other approaches, here is my question. 

I have a gallery based from a list called Teams.  The gallery works, as far as functionality, beautifully using this formula in which we are totaling some points earned and then ranking the gallery in descending order by rank. 

With(
{
records: //used to allow for team ranking
SortByColumns(
Search(
Filter(
Teams,
Gallery3_1.Selected.Category = "All" || Category = Gallery3_1.Selected.Category
),
txtSearch.Text,
"Title",
"Description"
),
"Total_x0020_Points_x0020_Earned",
Descending,
"Title",
Ascending
)
},//filter by topic and keyword text search
ForAll(
Sequence(CountRows(records)),
Patch(
Last(
FirstN(
records,
Value
)
),
{rowNumber: Value}
)
)
)//

 

However, I'd like to know if the following can be done.  Add a label in the same gallery with this formula, which is, of course, from a different list and then sort the gallery by the result of this label calculation.   I did try to replace the "Total_x0020_Points_x0020_Earned" in the first formula with the following formula without success -- but I did not spend a lot of time trying to resolve it.

Round(
Sum(
Filter(
'Activity Record',
TeamID = Text(ThisItem.ID)
),
Value(StarsEarned)
),
1
)

I'm concerned about the message I'm getting saying Sum is not supported but everything looks right.  

 

I know this would not be the best approach were this project long term, but it is about to wrap up and we just want to get this ranked correctly using the right number, which is not happening using a workflow and the first formula. 

 

Thanks for your thoughts on this...and I really hated to ask knowing this would be a band aid and hardly proper protocol for building an app. 

 

 

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    154,411 Most Valuable Professional on at

    Hi @CindyZ ,

    I cannot test this (and you do not need Round if you are sorting), but try this (you were also missing a bracket in your Sum formula)

    With(
     { 
     records:
     SortByColumns(
     Search(
     AddColumns(
     Filter(
     Teams,
     Gallery3_1.Selected.Category = "All" || 
     Category = Gallery3_1.Selected.Category
     ),
     "Activity",
     Sum(
     Filter( 
     'Activity Record',
     TeamID = Text(ID)
     ),
     Value(StarsEarned)
     )
     ),
     txtSearch.Text,
     "Title",
     "Description"
     ),
     "Activity",
     Descending,
     "Title",
     Ascending
     )
     },
     ForAll(
     Sequence(CountRows(records)),
     Patch(
     Last(
     FirstN(
     records,
     Value
     )
     ),
     {rowNumber: Value}
     )
     )
    )

     

    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

  • CindyZ Profile Picture
    on at

    @WarrenBelz  Thanks so much for the help on this.  I'm imputting it now, and it appears I'm hitting an error at the point of "Activity" Sum...Is there something missing or incorrect there?  

  • CindyZ Profile Picture
    on at

    Sorry....just saw your comment on the Sum bracket. 

     

     

  • CindyZ Profile Picture
    on at

    Thanks to Warren Belz for his help on this solution!  

    @WarrenBelz  Sorry for the delay in getting back with you!  Here is the code that worked (basically, just added the comma after the first Activity).  Thanks, as always, for your terrific help! 

     

    With(
    {
    records: SortByColumns(
    Search(
    AddColumns(
    Filter(
    Teams,
    Gallery3_1.Selected.Category = "All" || Category = Gallery3_1.Selected.Category
    ),
    "Activity",
    Sum(
    Filter(
    'Activity Record',
    TeamID = Text(ID)
    ),
    Value(StarsEarned)
    )
    ),
    txtSearch.Text,
    "Title",
    "Description"
    ),
    "Activity",
    Descending,
    "Title",
    Ascending
    )
    },
    ForAll(
    Sequence(CountRows(records)),
    Patch(
    Last(
    FirstN(
    records,
    Value
    )
    ),
    {rowNumber: Value}
    )
    )
    )

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!

Leaderboard > Power Apps

#1
Haque Profile Picture

Haque 103

#2
WarrenBelz Profile Picture

WarrenBelz 82 Most Valuable Professional

#3
wolenberg_ Profile Picture

wolenberg_ 67 Super User 2026 Season 1

Last 30 days Overall leaderboard