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

Creating an ID column that takes the previous ID and adds 1 to it

I need to create an ID column in my app that will take the ID of the previous item and add 1 to it. Essentially last submitted value plus one. I don't think it should be that hard to look up the previous value but I can't find an answer.

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @Turreaux 

The formula for manually creating the next ID in a datasource is 

 

First(Sort(datasource,ID,Descending)).ID+1

 

Since sort is delegatable for all connectors,  and while Last() and Max() are not, this formula will not run into problems with delegation, no matter how many items are in the datasource.
If I am manually assigning a value to an ID column in an edit form, I use the Coalesce() function. It tests each value in order until a value that is not blank and not an empty string is found.  The TextInput box in the ID card has the following formula:

 

Coalesce(Parent.Default,First(Sort(datasource,ID,Descending)).ID+1)

 

Since when an edit form is in New mode, the Parent.Default is null, then the next ID is assigned by the formula.  When the form is in Edit mode, the record will already have an ID so Parent.Default has value and the Coalesce() function will keep it.  ref. https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-isblank-isempty 

  

View solution in original post

3 REPLIES 3
kbilakanti
Resolver II
Resolver II

Hi,

Store the last saved response in a variable  which be a record. Get the ID column from the record and add plus 1 to it before pushing the current record.

Would this work across multiple users?

Hi @Turreaux 

The formula for manually creating the next ID in a datasource is 

 

First(Sort(datasource,ID,Descending)).ID+1

 

Since sort is delegatable for all connectors,  and while Last() and Max() are not, this formula will not run into problems with delegation, no matter how many items are in the datasource.
If I am manually assigning a value to an ID column in an edit form, I use the Coalesce() function. It tests each value in order until a value that is not blank and not an empty string is found.  The TextInput box in the ID card has the following formula:

 

Coalesce(Parent.Default,First(Sort(datasource,ID,Descending)).ID+1)

 

Since when an edit form is in New mode, the Parent.Default is null, then the next ID is assigned by the formula.  When the form is in Edit mode, the record will already have an ID so Parent.Default has value and the Coalesce() function will keep it.  ref. https://docs.microsoft.com/en-us/powerapps/maker/canvas-apps/functions/function-isblank-isempty 

  

View solution in original post

Helpful resources

Announcements
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

Top Solution Authors
Top Kudoed Authors
Users online (1,243)