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 / Flow - auto increment ...
Power Automate
Unanswered

Flow - auto increment a certain column of an added row

(0) ShareShare
ReportReport
Posted on by

Hi!

 

I am building a more complex flow in which everytime a form is submitted, a new excel row is generated. What I'm struggling with is that I want the first cell of the row to be an auto number (the previous row value +1).

 

I've looked for solutions online, I tried declaring a variable and then increment it by one, but it's the same problem, I din't know how to declare a variable starting value, so I'm getting the same number every time. Any ideas? Is there an expression which would yield the value of the previous row, same column + 1?

 

Thanks!

 

Screenshot.png

Categories:
I have the same question (0)
  • Verified answer
    ccc333ab Profile Picture
    1,144 on at

    Here is an approach: 

     

    1. Get the rows from your excel first, so you can find out the ID's that have been used. In my excel file I have a column called DisciplineID which is a counter like yours. I also order by DisciplineID in case your ID's are out of order. 

    ccc333ab_0-1625841938783.png

    2. I then use a LAST statement to get the very last row of this spreadsheet. 

    ccc333ab_1-1625842026614.png

    3. And then I add 1 to the column called DisciplineID that outputs from my compose statement. 

    ccc333ab_2-1625842076009.png

     

    Now you can just use the output of this compose statement for adding in the new ID in your "Add a row into a table" action. 

     

     

  • Community Power Platform Member Profile Picture
    on at

    Hey! Thank you so much for your kind response, it worked perfectly, not only that, but I also managed to extract the id and append it to the linked file name, which is extremely helpful to my company 🙂

     

    Cheers!

  • Trabajanus Profile Picture
    7 on at

    How can I adapt this in order to Update a row with consecutive ID's for rows that don't have them ?

  • ccc333ab Profile Picture
    1,144 on at

    Not 100% sure what you are asking. 

     

    Do you have an existing spreadsheet with a blank column and you want to have an ID added to it? Or does the existing spreadsheet have a column that has SOME IDs in it and you want to fill in the missing IDs? 

  • Trabajanus Profile Picture
    7 on at

    I do have a spreadsheet , that contains ID's already , and a flow that will continue to fill in information from another table but without the ID, what I want is to fill in the ID for the rows that get added  if that is possible 

  • ccc333ab Profile Picture
    1,144 on at

    Try this. Here are my two tables. 

    Table 1: FamilyWithID   

    ccc333ab_0-1643135225014.png

     

    Table 2: FamilyToAdd (doesn't have IDs)

    ccc333ab_1-1643135340498.png

     

    The flow would be: 

    1. List the rows in the table that has your IDs in it. Make sure you "ORDER BY" to ensure your IDs are in order as the code relies on that. (My ID field is called TestID).

    ccc333ab_8-1643136622896.png

     

    2. Then get the last row of your table with IDs. 

    ccc333ab_9-1643136681086.png

     

    3. Now initialize a variable with the last ID used. 

    ccc333ab_10-1643136712669.png

     

    4. Now list the rows present in your table without the IDs

    ccc333ab_4-1643135857285.png

    4. Now you'll want to loop through each row you want to add. 

    ccc333ab_5-1643135927655.png

     

    5. Increment your variable to the next ID number

    ccc333ab_6-1643135974151.png

    6. And then add your data into the original spreadsheet, using the variable as the ID.

    ccc333ab_7-1643136075924.png

    Now, this assumes you clear out the spreadsheet without IDs for every run. If you don't you'll need to put some checking in there to determine if the row has been added before or not. 

    Final Result: 

    ccc333ab_11-1643136910671.png

     

  • Trabajanus Profile Picture
    7 on at

    Thank you very much , that helped 

  • martii20 Profile Picture
    27 on at

    I tried coping these steps to my flow and I am getting an "Invalid Template" error message on the second function (compose add one to get new id)

     

    Error MessageError Message

     

    FunctionFunction

     

    Does anyone have any tips for fixing this? Thanks

  • ccc333ab Profile Picture
    1,144 on at

    Guessing as you didn't actually show your initial COMPOSE action (the one that you set your MOC value in), but I believe your equation should be:

     

    add(int(outputs('Compose')),1)

  • martii20 Profile Picture
    27 on at

    Okay, I tried that and it didn't work. Here's my whole flow:

     

    martii20_1-1693245911484.png   martii20_2-1693245915638.png

     

    I am trying to accomplish the same thing as the original post - when a new response is submitted, response details are collected in an Excel file and assigned an "MOC ID," which is just +1 from the previous row. 

     

     

     

     

     

     

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 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard