Get the next SharePoint list item ID in Power Apps

When creating our Power Apps we regularly use the inbuilt SharePoint item ID to uniquely identify a record.

 It is a common scenario to require the SharePoint ID before it has been assigned i.e. after form submission. 

There are two methods of achieving this:

Sort Method

This is the preferred method of obtaining the next SharePoint item ID as it is delegable. SharePoint will do the heavy lifting which is important for larger data sets.

The following formula gets the latest SharePoint ID:

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

The SharePoint list is sorted by ID in descending order. The First function returns the first record, we are interested in the ID column. We then increment by one to get the next ID.

Max Method

This Max operation is not supported in SharePoint so Power Apps will present a delegation warning (double blue lines underneath the function). This means the function won't work reliably on larger data sets.

Max(YourSharePointList,ID) +1

 

A Warning

Both of these methods find the highest ID in the list and increment by 1. This isn't necessarily going to be the ID SharePoint assigns to the next saved item. For example if the latest item in a list was deleted and that item had an ID of 5, the above methods would return 5 as the next ID as 4 + 1 = 5. However the next ID to be assigned to a saved item in SharePoint will be 6.