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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Auto incrementing IDs ...
Power Apps
Answered

Auto incrementing IDs with prefix (prefix from Dropdown list)

(0) ShareShare
ReportReport
Posted on by

Hello, 

I am a PowerApps beginner and I struggle to automatically generate an ID, which starts with a prefix.

Background is that I have a screen which is a new inspection form where the user can enter his findings. The form includes different data cards but the ones that are currently interesting for me are the following:

 

Component (Dropdown list) with the following entries:

A: Module1 

B: Module2

C: Module3

😧 Module4

 

ID (Text input):

Here I want to generate the automatic ID in the following format: 

Split(Dropdown.Selected.Value, ":") and 00xx

 

For example, if my list looks like:

ComponentID
A: Module1A001
C: Module3C001
A: Module2A002
A: Module2A003
😧 Module4D001

 

If the user enters a new finding and selects from the Component dropdown list: "A: Module1", I would like the ID "A004" to be automatically generated and visible in my Text Input ID (user should not be able to edit it).

If user chooses from the dropdown list "C: Module3", then "C002" should be generated, etc.

 

There are two steps to generate my ID, the first one being the split of dropdown.selected.value on ":" to keep only the first left character, the second being the incrementation but despite trying, I couldn't find a way to code it properly... 

 

Any help would be very much appreciated 🙂

Categories:
I have the same question (0)
  • anibra Profile Picture
    278 on at

    Where do the drop-down values come from? table, collection or they are fixed values?

  • CU15061124-0 Profile Picture
    on at

    Dropdown values are fixed values (In the Items property, I've defined the different entries 

    Items = ["A: Module1","B: Module2","C: Module3", "D : Module4"])

  • Verified answer
    WarrenBelz Profile Picture
    153,073 Most Valuable Professional on at

    Hi @Marine_C ,

    You did not state your data source here, but assuming SharePoint, you will have to call the column something other than ID (I have used IDField below). I have also assumed .Value as the output of the drop-down. I cannot test this, but it should be close to what you need

    With(
     {
     wComp:
     Left(YourDropdown.Selected.Value,1)
     },
     With(
     {
     wLast:
     Lookup(
     Sort(
     YourListName,
     ID,
     Descending
     ),
     StartsWith(
     Component,
     wComp
     )
     ).IDField
     },
     wComp & 
     Text(
     Value(
     Right(wLast,3)
     ) + 1,
     "000"
     )
     )
    )

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • anibra Profile Picture
    278 on at

    Hi @Marine_C ,

    assuming that you are showing the selected dropdown values and generated values in a gallery, my suggestion is as follows:

    In the onChange property of the dropdown define the formula: 

    Collect(
    var_list,
    {
    DD: Dropdown2.SelectedText.Value,
    Id: First(
    Split(
    Dropdown2.SelectedText.Value,
    ":"
    )
    ).Result & "00" & CountRows(
    Filter(
    Gallery6.AllItems,
    Title4.Text = Dropdown2.SelectedText.Value
    )
    ) + 1
    }
    );

     

    anibra_0-1655711812221.png

     

  • CU15061124-0 Profile Picture
    on at

    Hi @WarrenBelz,

    Thanks for the reply! You assumed right, my data source is a Sharepoint list and the .Value is the output I get from the dropdown (example: "A: Module1")

     

    I have renamed my column "ID" to "IDField" as you did, for me to understand your code. But I was wondering what is "ID" in your code then? 

     

    Moreover, I tested the code and got the following error:

    Marine_C_0-1655717415933.png

    DataCardValue7_2 being my Text Input, where I want to display my final ID:

    Marine_C_1-1655717489482.png

     

    Put I used your code in the Default property of the Text Input, maybe it is where there is the error...

     

  • CU15061124-0 Profile Picture
    on at

    Hi @anibra 

    Thanks for the inputs! My screen looks like this:

    Marine_C_2-1655717628506.png

    And I basically try to generate the automatic ID in the "IDField", which is a Text Input.

     

    From your code, I guess only the CountRows() part needs to be adjusted (?) (where there is a reference to the Gallery)

  • anibra Profile Picture
    278 on at

    @Marine_C  Instead of the gallery you can use your sharepoint list and instead of the collection var_list use set to set a variable which will be the Text value of your label. You need to count the available rows in order to know which id to generate

  • WarrenBelz Profile Picture
    153,073 Most Valuable Professional on at

    Hi @Marine_C ,

    Firstly, please tag whoever you want to assist you here - three-way conversations just confuse everyone.

    The ID is the ID column in SharePoint which I am simply sorting on Descending on to get the newest record (and hence the largest number) and then filtering on the prefix to get the right item. Also, if you want code examined, please post the entire actual code you are using in Text as well as what the error is stating. Before you do that, please check that you have applied your values correctly to the code posted as it appears valid to me.

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

  • CU15061124-0 Profile Picture
    on at

    Hi @WarrenBelz 

    Sorry for the three-way conversation, it was indeed hard to follow. I found out where my error was when implementing your code, thanks for the support, it is now working perfectly!

  • FeierCiprian Profile Picture
    20 on at

    Hi, @WarrenBelz 
    I have the same implementation but in Dataverse table. How can be implemented?
    thank you

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard