cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SophieBoucher Frequent Visitor
Frequent Visitor

change primary key power bi

Hello,

 

Anyone can tell me how we can change a colomn of Primary key in Power BI,

I have a table with 2 Colomn, i like to add an Index colomn and specify it to primary can, i can't do it.

 

Thank you 

10 REPLIES 10
Super User
Super User

Re: change primary key power bi

Why do you want to do this?  A primary key in Power Pivot is used to join a lookup table to a fact table.  There is no point doing this unless the key exists in both tables.  So it is not as simple as just adding a key.  The key must match, so an Index column alone wont help you.



* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
SophieBoucher Frequent Visitor
Frequent Visitor

Re: change primary key power bi

I want to change the primary key column to another column, because i applied an unpivot on my table and primary key has became not primary with duplicated values, and i need a colomn with identified values like Index, is it clearer?

SophieBoucher Frequent Visitor
Frequent Visitor

Re: change primary key power bi

PrtScr capture_2.jpg

That is the problem who appears

Moderator v-yuezhe-msft
Moderator

Re: change primary key power bi

Hi @SophieBoucher,

Could you please post the full error message in English and share sample data of your scenario?

Generally, we will need to create/define Primary key at data source level and then import it into Power BI.  Another option is to use DAX in Power BI to combine several columns so that each row has unique values.


Thanks,
Lydia Zhang

Community Support Team _ Lydia Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
odanovich Frequent Visitor
Frequent Visitor

Re: change primary key power bi

I'm receiving this same error... I made edits to my query and now I cant change the data model to resolve it because the data model is waiting for the query changes to be applied... but those cant be changed due to the error that the column is considered the Primary Key of the table....

 

error.PNG

Highlighted
odanovich Frequent Visitor
Frequent Visitor

Re: change primary key power bi

To get around this issue, I added a Step in my Query to remove duplicates on the particular column... this allowed me to successfully apply the query.  Then I loaded the data model, deleted the relationship.  Next I went back in and removed my Query Step: Removed Duplicate to bring back to the original table and now I am reapplying the proper relationship.   Phew!  Problem solved. Smiley Happy

ImaDAXman Frequent Visitor
Frequent Visitor

Re: change primary key power bi

It is likely because of the cardinality of your table relationship.  Try changing either from ManySmiley Surprisedne to One:Many (or vice versa).  

 

Also, make sure the cross filter direction is set to single instead of both.  The direction should be Dim > Fact.

Smizmar Frequent Visitor
Frequent Visitor

Re: change primary key power bi

In Query Editor:

1. Do your Unpivoting work.

2. Add Column; Index Column; From 0 or 1.  Call it Index.

3. Create a copy of the column that the editor thinks is your primary key.  Call it "Primary - Copy".

4. Delete the column that the editor thinks is your primary key (so delete "Primary" column in this example.) This will force the editor to assume a different primary key.  It will choose the Index column as your new primary key.

5. Apply your changes.

6. Go back and rename the "Primary - Copy" to its orignial name.

juan_pablo Frequent Visitor
Frequent Visitor

Re: change primary key power bi

Primary Keys have more uses than for relationships, for exmple to avoid circular dependencies when using CALCULATE in a calculated column.

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

Community News & Announcements

Community News & Announcements

Get your latest community news and announcements.

Virtual Launch Event

Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

Community Kudopalooza

Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Users Online
Currently online: 231 members 2,244 guests
Please welcome our newest community members: