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
csmathers
New Member

If column contains values from column in another table...

I have a table Person, and person table has a stateId field for birthplace and current address ('Id','BirthPlaceState','CurrentAddressState').  In SQL both fields are Foreign keys to the LookupTable with has ('Id','PersonFK','Value').  How can I get the state Value from the Lookup Table for both the birthplace State and the current address state?  

1 ACCEPTED SOLUTION

Hi @csmathers,



Following are the detail steps to use Merge Queries in Power Query in your scenario.

 

I assume you have the tables like below.

Person

p.PNG

State

s.PNG

1. Click "Edit Queries" in Home tab.

editorQuery.PNG

2. Select "Person" on Queries, and click Merge Queries.

merge.PNG

3. Select "BirthPlaceState" column for "Person" table, and select "State" table, "Id" column, click "OK".

merge2.PNG

4. Click the double arrow and select "Value", then click "OK".

arrow.PNG

5. Rename the added column.

rename.PNG

6. Repeat step 2, 3, 4, 5 for "CurrentAddressState". Last, click "Close&Apply".

close.PNG

Then you should be able to get a new "Person" table with state values of "BirthAddressState" and "CurrentAddressState".

newtable.PNG

 

Regards

View solution in original post

4 REPLIES 4
Greg_Deckler
Super User
Super User

You could do this several ways. You could import your other tables and form a relationship between your tables. You could also write your SQL such that you create a SQL statement that combines all of the tables together (join). You could also use Power Query to Merge all of your tables together (join).


@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the response, there is a relationship in sql server but Power Bi does not maintain the relationship because it only allows one related column from person to Lookup table.  If I try to add the 2nd relationship it gives me an error and says I can only have one.  

Yeah, I have a sql query to do it but I wanted give my power users the ability to add those columns using the fields selector.  I don't want to have to provide a sql query any time they want to add a query.  

What is Power Query? 

Hi @csmathers,



Following are the detail steps to use Merge Queries in Power Query in your scenario.

 

I assume you have the tables like below.

Person

p.PNG

State

s.PNG

1. Click "Edit Queries" in Home tab.

editorQuery.PNG

2. Select "Person" on Queries, and click Merge Queries.

merge.PNG

3. Select "BirthPlaceState" column for "Person" table, and select "State" table, "Id" column, click "OK".

merge2.PNG

4. Click the double arrow and select "Value", then click "OK".

arrow.PNG

5. Rename the added column.

rename.PNG

6. Repeat step 2, 3, 4, 5 for "CurrentAddressState". Last, click "Close&Apply".

close.PNG

Then you should be able to get a new "Person" table with state values of "BirthAddressState" and "CurrentAddressState".

newtable.PNG

 

Regards

That is just what I was looking for!!! Thanks so much!

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.