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 Groups of item...
Power Apps
Answered

Sorting Groups of items in a Gallery

(1) ShareShare
ReportReport
Posted on by 56
I have a gallery that I would like to sort by 2 dimensions, but I want to sort both groups of items and within the groups. The app is to help run a meeting where teams present updates on their assigned items, so I need the items grouped by the team so that they are presenting at the same time. However, the order the teams should go in to present their updates in should be determined by the oldest item on the list, and then the order the team themselves should go in when presenting their items is by priority.
 
After researching not seeing anything that would do what I want (might be out there but I can't figure out a good search phrase for what I'm trying to do), my next thought was to add a column that would assign the date of the oldest item within a group to all items in that group so that SortByColumns would automatically keep the teams together, but I can't figure out how to do that either.
 
Here's some example data unsorted:
Item Priority Team Age
ITEM10005 1 Team C 100 days
ITEM10021 2 Team A 44 days
ITEM10002 3 Team C 3 days
ITEM10035 4 Team E 135 days
ITEM10013 2 Team E 10 days
ITEM10014 1 Team M 23 days
 
This is how I'd like the data to be sorted in the gallery:
Item Priority Team Age
ITEM10013 2 Team E 10 days
ITEM10035 4 Team E 135 days
ITEM10005 1 Team C 100 days
ITEM10002 3 Team C 3 days
ITEM10021 2 Team A 44 days
ITEM10014 1 Team M 23 days
 
Team E has the oldest item on the list, so Team E presents first. Of the two items assigned to Team E, the first on the list is the higher priority one even though that's not the oldest. Team C has the next oldest item assigned to them, so they are second, even though they also have the newest item. Of the two items assigned to Team C, the higher priority one is first. Teams A and M have one each, so these are in order from oldest to newest.
 
Anyone have any idea how to do this?
Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    156,100 Most Valuable Professional on at
    Try this in the gallery Items
    With(
       {
          _Data1: 
          AddColumns(
             DataSource,
             _Age,
             Value(
                First(
                   Split(
                      Age,
                      " "
                   )
                ).Value
             )
          )
       },
       With(
          {
             _Data2: 
             AddColumns(
                GroupBy(
                   _Data1,
                   Team,
                   Grouped
                ),
                _Max,
                Max(
                   Grouped,
                   _Age
                )
             )
          },
          SortByColumns(
             AddColumns(
                _Data1,
                AgeSort,
                LookUp(
                   _Data2 As _Data,
                   _Data.Team = Team
                )._Max
             ),
             "AgeSort",
             SortOrder.Descending,
             "Priority",
             SortOrder.Ascending
          )
       )
    )
     
    Please click Does this answer your question 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 a Like.
    MVP (Business Applications)     Visit my blog Practical Power Apps    Buy me a coffee

     
  • RathwynAE Profile Picture
    56 on at
    So this worked but it broke basically everything else in my app... suddenly my OnClick setting of the record in the gallery to a variable isn't working, my patch function throws an error, etc. It's acting like I created a collection? Do I have to add lookups to all these functions to return the correct record? How will that impact performance?

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 325 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard