Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hello PowerBI community,
I know we need a column in one table which we can relate with the column in another table to establish a relation ship.
I have a peculiar requirement, where I need to establish a relation ship using one column of a table to multiple columns of another table.
Table 1:
Table2:
Is there anyway in power BI to relate these 2 tables?
Help is much appreciated. Thanks in advance
Solved! Go to Solution.
Hi @SriKandimalla ,
You can unpivot the second table. This way you will have also one column in the second table and can create a relationship.
Here is a link for unpivoting in PowerQuery: https://www.myexcelonline.com/blog/unpivot-data-using-excel-power-query/
Let me know if it fixes it.
Regards,
LC
Interested in Power BI finance templates? Check out my blog at www.finance-bi.com
Hi @SriKandimalla ,
To unpivot the table 2 as the picture below.
M code for your reference.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkktKcrPLFHSUTIEYiMoNgPzY3VA8jk5icVQYWMkbAaWLsjIT83LrICLIbAxWL44NbGkJCcVyDcBYlMUDJIvykzOyM3PS4EKWkINMoEryEstr8wvqoQaagJ1iCmYHRsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [City = _t, fruits = _t, Veggies = _t, meat = _t, dairy = _t, grains = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"City", type text}, {"fruits", Int64.Type}, {"Veggies", Int64.Type}, {"meat", Int64.Type}, {"dairy", Int64.Type}, {"grains", Int64.Type}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"City"}, "Attribute", "Value") in #"Unpivoted Other Columns"
Colse and apply, then we can create relationship between table 1 and table 2.
BTW, pbix as attached.
Hi @SriKandimalla ,
To unpivot the table 2 as the picture below.
M code for your reference.
let Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WSkktKcrPLFHSUTIEYiMoNgPzY3VA8jk5icVQYWMkbAaWLsjIT83LrICLIbAxWL44NbGkJCcVyDcBYlMUDJIvykzOyM3PS4EKWkINMoEryEstr8wvqoQaagJ1iCmYHRsLAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [City = _t, fruits = _t, Veggies = _t, meat = _t, dairy = _t, grains = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"City", type text}, {"fruits", Int64.Type}, {"Veggies", Int64.Type}, {"meat", Int64.Type}, {"dairy", Int64.Type}, {"grains", Int64.Type}}), #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Changed Type", {"City"}, "Attribute", "Value") in #"Unpivoted Other Columns"
Colse and apply, then we can create relationship between table 1 and table 2.
BTW, pbix as attached.
Thank you for your detailed solution. Really appreciate it.
In addition to this question, what if I have additional columns and I have to still establish a relationship with the 2 tables?
Hi @SriKandimalla ,
Can you share more about the additional columns and what you would like to achieve?
Hi @SriKandimalla ,
You can unpivot the second table. This way you will have also one column in the second table and can create a relationship.
Here is a link for unpivoting in PowerQuery: https://www.myexcelonline.com/blog/unpivot-data-using-excel-power-query/
Let me know if it fixes it.
Regards,
LC
Interested in Power BI finance templates? Check out my blog at www.finance-bi.com
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
108 | |
100 | |
78 | |
64 | |
58 |
User | Count |
---|---|
148 | |
113 | |
97 | |
84 | |
67 |