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 / 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
    155,779 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
    155,779 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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 477

#2
WarrenBelz Profile Picture

WarrenBelz 341 Most Valuable Professional

#3
11manish Profile Picture

11manish 317

Last 30 days Overall leaderboard