Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Apps - Microsoft Dataverse
Unanswered

Possibility of adding unique constraint for combination of two columns based on one column value

(0) ShareShare
ReportReport
Posted on by 46

Dear Community, 

 

Is it possible for a Dataverse table to add unique constraint as combination of two columns based on the column value? 

To be more clear please find the example below:

Combination of ColumnA and ColumnB should be unique in the Table_X  if ColumnB value is 1 (true).

Table_X

 

-----------------------------------
|ID(key)|ColumnA(int)|ColumnB(bit)|
-----------------------------------
| 1 | 250 | 1 |
-----------------------------------
| 2 | 301 | 1 |
-----------------------------------
| 3 | 250 | 0 |
-----------------------------------
| 4 | 250 | 0 |
-----------------------------------

 

As you can see in the Table_X I can have only one record with the combination: ColumnA = 250 and ColumnB = 1 (record with ID=1). However I can have many records with combination of  ColumnA = 250 and ColumnB = 0 (records with ID equals 3 and 4)

In SQL server, I would simple create an unique index to achieve this:

 

CREATE UNIQUE NONCLUSTERED INDEX UQ_INDEX_COLUMNA_COLUMNB_TRUE
ON Table_X(ColumnA, ColumnB)
WHERE ColumnB = 1;

 

 

Please note that I know how to accomplish the same goal from the application side. I'm looking here to see if it is possible to do it on the entity level. I'm also aware that I can create Keys for Entity(Tables) but I don't see how to include specific value for ColumnB.

 

Thank you!

  • a33ik Profile Picture
    3,304 Most Valuable Professional on at
    Re: Possibility of adding unique constraint for combination of two columns based on one column value

    Hello,

    The only way I see is to create a "Conditional" alternate key (just a theory, never tried it because I never had such a scenario). Here is how it might be architected:

    1. Create a new field that will serve as a placeholder for the key value.

    2. Create an alternate key that will contain only the field created in step 1.

    3. Create a sync plugin or real-time workflow that based on the data in the record will update the value of field 1 based on the condition. So if "Column B" equals 1, copy the value of "Column A" to the field created in step 1 and leave it blank if the condition is not met.

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Apps - Microsoft Dataverse

#1
mmbr1606 Profile Picture

mmbr1606 22 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 17

#3
ankit_singhal Profile Picture

ankit_singhal 11 Super User 2025 Season 1

Overall leaderboard

Featured topics