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 / Give a (smart) index t...
Power Apps
Answered

Give a (smart) index to each record in a Gallery

(1) ShareShare
ReportReport
Posted on by 70

Hello community,

 

I'm using this code in the Items property of a Gallery:

 

With(
 {
 wList: 
 Filter(Sort(GroupBy('Challenge Leaderboard',"Title","DistinctRecords"),Sum(DistinctRecords,Points),SortOrder.Descending), Sum(DistinctRecords, Points) >= LeaderboardMinimum)
 },
 ForAll(
 Sequence(CountRows(wList)),
 Patch(
 Index(
 wList,
 Value
 ),
 {RowNo: Value}
 )
 )
)

My SPO List has 4 columns ("Title" --> string column with user email, "Player" --> person-type column, "Week" --> choice column that can take Week 1, Week 2, Week 3, Week 4 values and "Score" --> number column, the score of each player for each week.

 

Using this Items property code, I can then have my gallery display the total score for each player (i.e. the sum of his weekly scores) and an index (called RowNo) that is 1 for the first row, 2 for the second row, 3 for the third row in the gallery and moving on...

 

As a result, I have a gallery that looks like:

 

1. Paul --> 30 points

2. Marco --> 30 points

3. Andrew --> 25 points

4. Natalie --> 20 points

5. Georgia --> 20 points 

 

etc. 

 

I want to somehow update this code so that the row index is the same for people with the same sum of points i.e.

 

1. Paul --> 30 points

1. Marco --> 30 points

2. Andrew --> 25 points

3. Natalie --> 20 points

3. Georgia --> 20 points

 

any thoughts?

Categories:
  • Verified answer
    CarlosFigueira Profile Picture
    Microsoft Employee on at

    You can use yet another grouping (by number of points) to find the row number, and then ungroup that, as shown in the expression below:

    Ungroup(
     With(
     { sortedGroup: Sort(
     GroupBy(
     Filter(
     AddColumns(
     GroupBy('Challenge Leaderboard', "Title", "DistinctRecords"),
     "TotalPoints",
     Sum(DistinctRecords,Points)
     ),
     TotalPoints >= LeaderboardMinimum
     ),
     "TotalPoints",
     "DistinctTotalPoints"
     ),
     TotalPoints,
     SortOrder.Descending
     )},
     ForAll(
     Sequence(CountRows(sortedGroup)),
     Patch(
     Index(sortedGroup, Value),
     { RowNo: Value }
     )
     )
     ),
     "DistinctTotalPoints"
    )

    Noticed that we had to use the AddColumns function to add a new column for the total points (so that we could group by it). With it you can have a gallery that displays what you want:

    ForumPost001.png

    Hope this helps!

  • AntDim Profile Picture
    70 on at

    hi @CarlosFigueira - thank you so much for your response. This looks to be working!

     

    One minor addition I would make to your code: after Ungroup, the sorting of the records seems to be no longer working. I was getting the correct RowNo index as desired, but the records were unsorted. Therefore, I just updated the code to Sort (Ungroup (...), Sum(DistinctRecords, Points), SortOrder.Descending) and this is now working perfect!

     

    Don't know if there would be another way to do this without adding this extra line of code? Thank you very much for your great help again. 

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

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 248 Super User 2026 Season 2

#2
WarrenBelz Profile Picture

WarrenBelz 192 Most Valuable Professional

#3
Mohsin Ali Profile Picture

Mohsin Ali 135

Last 30 days Overall leaderboard