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 Automate / Add auto increment a n...
Power Automate
Unanswered

Add auto increment a number column

(0) ShareShare
ReportReport
Posted on by 42

Hello everyone,

 

I have over 2000 rows on SharePoint List and I created a column called rowCount, as of now I only have number 1 until 100, how do I easily increment and make the next empty row 101 and so on. I would also like to automatically change the number if in case a row has been deleted, for example, if I have 1 to 100 and number 99 is deleted, the previous number 100 will change to number 99 basically the last max number will be 99 and there is no skip in the counting.

 

Please help how to achieve this and supply the remaining empty rows with the correct counting.

 

Categories:
I have the same question (0)
  • rzaneti Profile Picture
    4,241 Super User 2025 Season 2 on at

    Hi @heyjay ,

     

    You have different ways to achieve this same result. The most obvious alternative would be use a 'When an item is created or modified' trigger that captures all items from the List and reassign all of the "Row count" records. However, this approach would result in an infinite loop, as you would be updating each one of the "Row count" records and, consequently, calling the trigger again (and again, and again...). 

     

    The solution that I recommend you is to create a recurrent flow, that will run every day (or every hour, or every minute, according to your business requirement). This flow will first compare if the "Row count" for the last record matches to the List quantity of records and, if not, update each row of it.

     

    Overview 

    For this example, I will be working with this SharePoint List. My goal here is to populate the "RowCount" column with Power Automate, and update it if we have any new row or when if a record is deleted. 

    rzaneti_0-1688505982529.png

     

    Step 1 - Set your Recurrent trigger:

    Create a 'Recurrence' trigger and set the desired schedule for your runs:

    rzaneti_9-1688507424741.png

     

     

    Step 2 - Initialize a "count" variable:

    I'm assuming that you want to start to count your records in 1, so the first step is to initialize an Integer variable for it, with an initial value of 1: 

    rzaneti_1-1688506087612.png

     

    Step 3 - Get your List records:

    Then you use the action 'Get Items' from SharePoint connector to pull all records from your List:

    rzaneti_2-1688506135880.png

     

    Step 4 - Test the List qty of records:

    Now you need to capture (1) the total quantity of records in your List and (2) the 'RowCount' of the last record. If the both values matches, your column has the correct values and the flow can stop here. If not, we want to reassign the correct 'RowCount' to all records.

     

    So you will use a Condition action to compare the values:

    rzaneti_3-1688506337290.png

     

    In the right side of the condition, use this expression: length(outputs('Get_items')?['body/value'])

    In the left side of the condition, use this expression: last(outputs('Get_items')?['body/value'])?['RowCount']

     

    • length: By using this expression, you are getting the "length" of an array. The 'body/value' property is an array with all records, so we will return the total quantity of records. 
    • last: This expression will returns the last element from an array. As we are passing the 'body/value' property as argument, we will be accessing the details of the last row of the list 
    • ?: Please, do not forget to add this question mark before the 'RowCount'! In case of the last record of your list have an empty 'RowCount', this question mark will prevent the flow to fails. 
    • ['RowCount']: By using 'last', you accessed the List record, and by using this property, you are accessing exactly the value of the 'RowCount' of your last record. 

     

    Step 5 - Looping the records:

    In the "if no" block of your Condition action, add an 'Apply to each' loop, passing the 'value' property from 'Get Items' action. By doing this, you will access each element from the list and perform a specific task on it.

    rzaneti_4-1688506798749.png

     

    Step 6 - Updating 'RowCount': 

    Now it's time to actually update your List! Inside the loop, add an 'Update item' action from SharePoint connector and add the 'ID' dynamically, reffering to you 'Get Items' action (it will automatically pull the ID of the current loop iteration). 

     

    For the 'RowCount' input, enter the Integer variable that you created in Step 2. In this action, you can edit any other field from your List record (if you want). 

     

    Still inside the 'Apply to each' block, add an 'Increment variable' action, passing your Integer variable and 1 as value. It will make sure that your variable, that currently values 'x', will be valuing 'x+1' in the next loop iteration:

    rzaneti_11-1688507525134.png

     

     

    Output:

    After running the flow, this was the output:

    rzaneti_6-1688507109717.png

     

    If I add a new record and run the flow again, it will reassign the 'RowCount' to each entry:

    rzaneti_7-1688507252307.png

     

    If I delete a record, it also will apply the changes to 'RowCount' (I deleted 3 random records in the example below):

    rzaneti_8-1688507374880.png

     

    Complete flow desing:

    rzaneti_10-1688507492340.png

     

     

    Avoiding the Infinite Loop

    As the approach above uses a recurrent trigger, it will prevent you to face the infinite loop. However, if you still want to move forward with the 'When an item is created or modified', I recommend you to first investigate some alternatives to prevent the infinite loop. I recently wrote this article about it, but I want to let you know since right now that it does not contains a solution for a flow that updates several rows at once 😥http://digitalmill.net/2023/06/27/bypassing-the-sharepoint-lists-infinite-loop-in-power-automate/

     

     

    Let me know if it works for you or if you need any additional help!

     

    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.

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 Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard