web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Apps
Answered

Generate Unique ID

(0) ShareShare
ReportReport
Posted on by 143

In my app, everytime a user creates a form, that form is given an ID. This ID is based on the number of forms currently in the datasource + 1. Meaning if there are currently 10 forms in the datasource, the next created form is generated at 11.

 

My app also has a delete form function, that deletes the form based on its ID. The problem here is that if a newer form is deleted, such as 9 (and assuming there are 11 forms in the datasource), my app will count that there are 10 forms in the datasource and generate the newest form at ID = 11. So now if that form needs to be deleted, there are two ID 11s, meaning that both will be deleted.

 

I'm wondering if there is a way to lookup which numbers are unused and assign that unused number as the ID? Or if there is a way to bump the IDs down (if 9 is deleted, 10 becomes 9 and 11 becomes 10)? I am using excel as my datasource.

Categories:
I have the same question (0)
  • Verified answer
    CarlosFigueira Profile Picture
    Microsoft Employee on at

    There's no simple way to find an unused number (more on that below). But you can find the "next number" by using the Max function to get the higher number and increment it. Something along the lines of the code below:

    Patch(
     forms,
     Defaults(forms),
     {
     ID: Max(forms, ID) + 1,
     Name: TextInput1.Text,
     Phone: TextInput2.Text,
     ...
     })

    When you delete a form from your table, you'll get "missing IDs", but that's usually ok.

     

    There is a way to find the first "unused" ID, using the formula below, but it's not very reliable. The idea is to create a collection with all numbers from 1 to the maximum number of forms that you may have (the '...' below would need to be replaced with the actual numbers). If you believe that you'll never have more than 100 rows in your Excel table, then that would work, but that's an assumption that you can make and be broken in the future, so I wouldn't really recommend that.

    Min(
     Filter(
     [1,2,3,4,5,6,7,...,99,100], !(Value in forms.ID)),
     Value)
  • NPrice99 Profile Picture
    1,302 on at

    Hi

     

    Which event do I hang the Patch Command  off ?

     

    Thanks

     

    Nigel

  • CABIRD Profile Picture
    234 on at

    Thank you @CarlosFigueira

     

    I'm still thinking through the best solution to my question. While my original thought is OK for a single user if multiple users were to be using the app form then, when users submit the audit form to SharePoint I'm assuming SharePoint rightly won't accept the user app assigned ID as users would be submitting the same number because users would have acquired the same last ID number. 

     

    Can I assume I use  - Patch( forms, Defaults(forms), { ID: Max(forms, ID) + 1, Name: TextInput1.Text, Phone: TextInput2.Text, ... }) will find the last ID used in the SharePoint list then in Power Apps add 1 to the ID number then when the form is submitted the ID plus 1 number is used? 

     

    Not as easy as I thought and my research suggests there isn't an answer.

  • fer23gs Profile Picture
    2 on at

    I have the same problem

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @fer23gs @CABIRD 

     

    I have the same problem too was wondering if there is any work around to stop duplicating the ID when multiple users are submitting the form?

     

     

  • McCall Saltzman Profile Picture
    Microsoft Employee on at

    I would suggest if you need a truly unique ID, incrementing numbers isn't the way to do that. Try using the GUID() function to generate ids.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard