cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Frequent Visitor

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
Highlighted
Super User III
Super User III

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

View solution in original post

2 REPLIES 2
Highlighted
Super User III
Super User III

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

View solution in original post

Highlighted
Frequent Visitor

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
Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

Power Platform ISV Studio

Power Platform ISV Studio

ISV Studio is designed to become the go-to Power Platform destination for ISV’s to monitor & manage published applications.

Upcoming Events

Experience what’s next for Power Automate

See the latest Power Automate innovations, updates, and demos from the Microsoft Business Applications Launch Event.

Users online (6,422)