Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
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. 
  • WarrenBelz Profile Picture
    148,546 Most Valuable Professional on at
    Labeling Items in a List in Order
    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.
  • CSilva Profile Picture
    on at
    Labeling Items in a List in Order
    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? 
  • Suggested answer
    WarrenBelz Profile Picture
    148,546 Most Valuable Professional on at
    Labeling Items in a List in Order
    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

     

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1