web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Labeling Items in a Li...
Power Apps
Suggested Answer

Labeling Items in a List in Order

(1) ShareShare
ReportReport
Posted on by
Hello, I currently have an application that collects hundreds of items into a SharePoint list. Although the items are tagged with numbers (SORTID) in ascending order, those numbers aren't always sequential (ex: 1, 2, 3, 6, 88, 100). 
 
Recently, there has become a need to grab these records in the correct order, then update the SORTID to be in sequential ascending order (1, 2, 3, 6, 88, 100 needs to become 1, 2, 3, 4, 5, 6). 
 
Is there a way to patch those items from start to finish in order? I have been trying to use an incrementing variable in a ForAll statement, but haven't had any luck. 
 
Any help is greatly appreciated. 
I have the same question (0)
  • Suggested answer
    WarrenBelz Profile Picture
    153,061 Most Valuable Professional on at
    Hi CSilva,
    This works here when tested.
    With(
       {
          _Numbers: 
          With(
             {
                _List: 
                Sort(
                   SPListName,
                   SORTID
                )
             },
             ForAll(
                Sequence(CountRows(_List)),
                Patch(
                   Index(
                      _List,
                      Value
                   ),
                   {NewNo: Value}
                )
             )
          )
       },
       Patch(
          SPListName,
          ForAll(
             _Numbers As _Data,
             {
                ID: _Data.ID,
                SORTID: _Data.NewNo
             }
          )
       )
    )
    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

     
  • CSilva Profile Picture
    on at
    Thank you for the response, @WarrenBelz. 
     
    When I use the example you gave while working with a collection, I get an error stating, "The data source supplied to the function is invalid." Do you know why that is? 
  • WarrenBelz Profile Picture
    153,061 Most Valuable Professional on at
    Works fine here - I also used a collection (ensure there is an ID field in it). You only need to replace SPListName with your data source (two places). Also ensure that you have the SORTID numeric field in the table.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 711 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 319 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard