Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Sorting Groups of items in a Gallery

(1) ShareShare
ReportReport
Posted on by 54
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?
  • RathwynAE Profile Picture
    54 on at
    Sorting Groups of items in a Gallery
    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?
  • Verified answer
    WarrenBelz Profile Picture
    146,651 Most Valuable Professional on at
    Sorting Groups of items in a Gallery
    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

     

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

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,651 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 65,999 Most Valuable Professional

Leaderboard