Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Learn from the best! Meet the four finalists headed to the FINALS of the Power BI Dataviz World Championships! Register now

Reply
leo124
New Member

How to preserve or restore a unique primary key after pivoting

Hi all,

I loaded an Excel file into Power BI that originally had a unique primary key, and I wanted to create a 1-to-many relationship with two other tables. However, after unpivoting, the primary key started appearing multiple times in the column. I had to perform the unpivoting, but now the primary key is no longer unique. How can I find a way to keep the primary key usable despite this?

If you need more information, just let me know.

1 ACCEPTED SOLUTION
SamWiseOwl
Super User
Super User

Hi @leo124 

You can split the data into 3 tables.

Unique table - the primary key and any other unique information

Join table - unique id and the pivotid

Pivot table - pivotid for each row and the pivoted data

SamWiseOwl_0-1754554897945.png

 

I've attached a sample file with the Query Editor steps.

SamWiseOwl_1-1754555008701.png

 


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @leo124,

Thanks for reaching out to the Microsoft fabric community forum. This is expected behaviour after an unpivot, the unpivot operation creates multiple rows per original record, so the original primary key will appear multiple times in that table. To keep a true unique primary key you should separate the unique attributes from the repeated (pivoted) rows. As @SamWiseOwl responded to your query, kindly go through the response and chekc if your issue can be resolved.

 

I would also take a moment to thank @SamWiseOwl, for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.

 

If I misunderstand your needs or you still have problems on it, please feel free to let us know.  

Best Regards,
Hammad.

Anonymous
Not applicable

Hi @leo124,

As we haven’t heard back from you, so just following up to our previous message. I'd like to confirm if you've successfully resolved this issue or if you need further help.

If yes, you are welcome to share your workaround so that other users can benefit as well.  And if you're still looking for guidance, feel free to give us an update, we’re here for you.

 

Best Regards,

Hammad.

Anonymous
Not applicable

Hi @leo124,
Hope everything’s going smoothly on your end. As we haven’t heard back from you, so I wanted to check if the issue got sorted.
Still stuck? No worries just drop us a message and we can jump back in on the issue.

 

Best Regards,

Hammad.

Anonymous
Not applicable

Hi @leo124,
We noticed there hasn’t been any recent activity on this thread. If you still need support, just drop a reply here and we’ll pick it up from where we left off.

 

Best Regards,

Hammad.

SamWiseOwl
Super User
Super User

Hi @leo124 

You can split the data into 3 tables.

Unique table - the primary key and any other unique information

Join table - unique id and the pivotid

Pivot table - pivotid for each row and the pivoted data

SamWiseOwl_0-1754554897945.png

 

I've attached a sample file with the Query Editor steps.

SamWiseOwl_1-1754555008701.png

 


If you are happy with this answer please mark as a solution for others to find !

Kudos are always appreciated! Check out our free Power BI video courses.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

February Power BI Update Carousel

Power BI Monthly Update - February 2026

Check out the February 2026 Power BI update to learn about new features.