cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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
New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

New Power Super Users

Congratulations!

We are excited to announce the Power Apps Super Users!

Power Apps Community Call

Power Apps Community Call: February

Did you miss the call? Check out the Power Apps Community Call here.

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