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

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.

Reply
SriKandimalla
Helper I
Helper I

Can i create a relation between 2 tables using one coulmn against multiple columns?

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:

Table1Table1

Table2:

Table2Table2

Is there anyway in power BI to relate these 2 tables?

Help is much appreciated. Thanks in advance

2 ACCEPTED SOLUTIONS
lc_finance
Solution Sage
Solution Sage

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

View solution in original post

v-frfei-msft
Community Support
Community Support

Hi @SriKandimalla ,

 

To unpivot the table 2 as the picture below.

Capture.PNG

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.

 

2.PNG

BTW, pbix as attached.

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

4 REPLIES 4
v-frfei-msft
Community Support
Community Support

Hi @SriKandimalla ,

 

To unpivot the table 2 as the picture below.

Capture.PNG

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.

 

2.PNG

BTW, pbix as attached.

 

 

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

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?

lc_finance
Solution Sage
Solution Sage

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.