Showing results for 
Search instead for 
Did you mean: 
Frequent Visitor

Auto update an incremental ID to a collection

HI there, 


I have a collection which i am going to patch to my CDS but before that i need to increment a number on a each row , if a another column equals something so : 


UpdateIf( collection1, ThisRecord.NewExistingComponent = "New Part", { Counter: Counter + 1 } )


So if NewExisitingComponent = NewPart then incremenral Counter by 1. So there maybe 50 rows in a colleciton so therefore the Counter row needs to go from 1 to 50 if the other column = "new part" 


I am really struggling with this at the moment. 

Super User III
Super User III


Using this code you can create a new collection called 'mySolution' that includes a row number

//Row counter collection

//Row number code
ClearCollect(mySolution, AddColumns(collection1, "Counter", 0));
    Patch(mySolution, LookUp(mySolution, RowNumber=0), {Counter: First(rowCounter).Value});
        {Value: First(Sort(mySolution,Counter,Descending)).Counter + 1}



I adapted the solution from the code on my website


Please click "Accept as Solution" if my post answered your question so that others may find it more quickly. If you found this post helpful consider giving it a "Thumbs Up."

Seems reasonable and it works great -  thanks ! It brings in all the numbers 🙂

What if I wanted it on a query ? So If a column = yes in the gallery and then add the number. if the column contained anything else then ignore ? 


any help would be awesome 



Helpful resources

News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.


Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (10,966)