cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
DanielT
Level: Powered On

Highest Number in a column

Hi,

So I'm hoping someone can help me. I am trying to create a project number generator. So basically in SharePoint, a user would fill out the New form and it will generate a number for you based on the what the next highest number is. I have found a few tutorials and I can get it the number to increment based on the ID. However, this does not solve the problem where someone creates a number then deletes the row. This will lead to it skipping a number the next time an item is created.

Is there a way to calculate the highest number in a column and add 1? Can I loop through each row if needed to find the highest number?

1 ACCEPTED SOLUTION

Accepted Solutions
Super User
Super User

Re: Highest Number in a column

@DanielT 

One way to approach this is to use a Get items action.  Configure it to return just one item and sort in descending order on your column.  That value will be the highest number now in that column.

In my example, I reference the ID, but you could reference any numeric column.  You might want to create a variable and stuff the value in a variable.

 

MaxNumber.jpg

 

Alternatively, you could maintain a second list with one entry that just stores the last number used.  When you need a new number (next number), you can reference the list and then update it by incrementing the number by one.

 

If you have a high volume of transactions, norther of these are a great idea as it could generate duplicates.  However, they will work if it you don't have a high volume of transactions.

 

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
2 REPLIES 2
Super User
Super User

Re: Highest Number in a column

@DanielT 

One way to approach this is to use a Get items action.  Configure it to return just one item and sort in descending order on your column.  That value will be the highest number now in that column.

In my example, I reference the ID, but you could reference any numeric column.  You might want to create a variable and stuff the value in a variable.

 

MaxNumber.jpg

 

Alternatively, you could maintain a second list with one entry that just stores the last number used.  When you need a new number (next number), you can reference the list and then update it by incrementing the number by one.

 

If you have a high volume of transactions, norther of these are a great idea as it could generate duplicates.  However, they will work if it you don't have a high volume of transactions.

 

 

 

If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

Scott
Highlighted
DanielT
Level: Powered On

Re: Highest Number in a column

Hi Scott,

Thanks for your help. I finally was able to achieve what I wanted used the Get items function you recommended. I sorted "Current_Numb desc" and set Top Count to 1. Then using the Update Item function, I set Current_Numb to

add(first(body('Get_items')?['Value'])?['Current_Numb'],1). This made it so I can delete with no problems and the sequence will remain in tact.
 
Thanks again for the help.

Helpful resources

Announcements
firstImage

Microsoft Business Applications Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

firstImage

Watch Sessions On Demand!

Continue your learning in our online communities.

Power Platform 2019 Release Wave 2 Plan

Power Platform 2019 Release Wave 2 Plan

Features releasing from October 2019 through March 2020

thirdimage

Flow Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Flow Community Video Gallery!

Users Online
Currently online: 106 members 4,436 guests
Please welcome our newest community members: