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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
cinthiafkc
New Member

Relationship between three tables

Hi everyone!

 

I have a Fact table with a column which contain a foreign key.

This column may contain IDs that references to the Dimension City Table (whose DID countains 7 digits) or to the State Dimension Table (ID has 2 digits).

Someone could help on how should I make the relationship between the Fact Table and the Dimensions one in this case?

Thank you!!!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @cinthiafkc ,

 

Please follow these steps:

 

1. Add a Custom column based on the length of the ID_Entity column:

=if Text.Length(  Number.ToText( [ID_Entity])  )=2 then "ID_State" else "ID_City"

Eyelyn9_0-1632276420427.png

2.Click Custom column-->Pivot columns-->use ID_Entity as Values

Eyelyn9_1-1632276499424.png

 

After applying these changes, the relationships would be automatically built:

Eyelyn9_2-1632276625287.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Hi @cinthiafkc ,

 

Please follow these steps:

 

1. Add a Custom column based on the length of the ID_Entity column:

=if Text.Length(  Number.ToText( [ID_Entity])  )=2 then "ID_State" else "ID_City"

Eyelyn9_0-1632276420427.png

2.Click Custom column-->Pivot columns-->use ID_Entity as Values

Eyelyn9_1-1632276499424.png

 

After applying these changes, the relationships would be automatically built:

Eyelyn9_2-1632276625287.png

 

Best Regards,
Eyelyn Qin
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

@cinthiafkc Can you provide some example data? Seems like you should split that column into two maybe. Either that or perhaps combine your city and state dimensions. Hard to be sure with the information provided.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler 
The column ID_Entity of Investment Table is the one which contains both ID_city and ID_State

cinthiafkc_1-1632081181562.pngcinthiafkc_2-1632081191152.png

 

cinthiafkc_3-1632081208616.pngcinthiafkc_4-1632081216084.png

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.