Forum Discussion

GiangLe's avatar
GiangLe
Helper I
8 years ago
Solved

composite primary key

Hi everyone,    I'm quite new to Power BI and it's everyday story that i stumble upon something new which is good. My today question is about data modelling. In many to many relationships, it is a...
  • GeorgeBuster's avatar
    8 years ago

    Hi GiangLe,

     

    As you know, in Power BI you need a single column to link two tables (you can't define a key with two columns as you can in common databases). This column has necessarily to have unique values on one side of the relationship because Power BI doesn't work directly with a "many to many" relationship. In conclusion,  you will need to create a key using two columns with CONCATENATE or create a table with unique values between tables with non-unique values.

    Example: You have two fact tables with the sales of your employees and other with the wages of them, both have two columns with the name and surname of the employees. Firstly, you can define a primary key concatenate their name and surname and secondly, you need two create a table between them with the unique values of each employee. In that way, you will have a many (sales table) to one (employee table) relationship and a one (employee table) to many (wages table) relationship and PowerBI will work perfectly.