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 Platform Community / Forums / Power Apps / Make primary name unique
Power Apps
Answered

Make primary name unique

(0) ShareShare
ReportReport
Posted on by 25

I understand the difference between the primary name column and the primary key in tables, however I don't know how to make sure the primary name column is unique.

 

In my use case I have an "Item Number" which should be unique and seems like the best choice for primary name. However I know that the primary name column does not enforce uniqueness.

 

How can I ensure that if I set Item Number as the primary name column that it is unique?

Alternatively, should I choose something else for the primary name column and set item number elsewhere?

 

Thanks

 

 

Categories:
I have the same question (0)
  • timl Profile Picture
    36,785 Super User 2026 Season 1 on at

    Hi @rmcmun 

    I assume that you're referring to a Dataverse table.

    To enforce uniqueness on your "Item Number" column, you would define a key on this column. The details of how to do this are beneath.

    https://docs.microsoft.com/en-us/powerapps/maker/data-platform/define-alternate-keys-portal

     

  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @rmcmun 

    There are a couple of ways to do this.  To create a unique number you could set a TextInput box on a form with the value in the card assigned to the item ID.

     

     

     

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

     

     

     

    This would allow for a New item (ie. Parent.Default would be null) to be assigned the next ID number but when the form is in Edit mode the ID would be retained. I either hide this card or make it Disabled so that a user can't change the value.

    To prevent a duplicate in the Primary Name column from being assigned, I put this code in the OnSelect property of the button that saves the record. 

     

     

     

    If(
     IsBlank(
     Lookup(datasource,Lower(Trim(PrimaryName))=Lower((Trim(TextInput1.Text))
     )
     ),SubmitForm(
     Form1
     ),
     Notify(
     "There is already an item with that name in the database. Please change the 
     item name.", Error
     )
    )

     

     

    Lower(Trim(...  is used to prevent users from adding the same name but with a space or changing the case.  

    In the OnSuccess property of the form Notify("Your item has been successfully added", Success)

    One of my general database design principles is that the unique Primary key of a table should not have any meaning and is not revealed to the user. 

     

  • rmcmun Profile Picture
    25 on at

    Great, thanks so much.

    Actually both of these answer the main question as I am looking to both enforce uniqueness at the table level (which it seems I can do by setting it as a key), and also to generate unique rows in a form.


    Thanks for the help!

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 551

#2
WarrenBelz Profile Picture

WarrenBelz 430 Most Valuable Professional

#3
Valantis Profile Picture

Valantis 298

Last 30 days Overall leaderboard