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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
martinnilsson
Frequent Visitor

Joining multiple columns in relationship model using all primary keys

Hi,

I am a newbie to Power BI.  I imported two separate data sources, one with sales data and one with open orders data.  I would like to join these two data sources to be able to view open orders data in realtion to the sales data.

In a database environment I would join the two tables using the primary keys (Division, Year, Month, BU, PG, Cust no & Item no) to see the Qty, Amount, Cost, Qty_on_order & Value on the same row.

 

Can this be done in Power Query or is it a better solution to create the query in my database environment and import the query result to Power BI?

 

Sales data table

DivisionYearMonthBUPGCust noItem noQtyAmountCost
10020251302001234ABC1010050
10020251313009999ABC1010050
20020252301001234XYZ5200150

 

Open Orders table

DivisionYearMonthBUPGCust noItem noQty_on_orderValue
10020251302001234ABC1005000
20020252301001234XYZ101500

 

Result table after joining above tables

DivisionYearMonthBUPGCust noItem noQtyAmountCostQty_on_orderValue
10020251302001234ABC10100501005000
10020251313009999ABC1010050  
20020252301001234XYZ5200150101500

 

Kind regards,

-M.

 

 

2 ACCEPTED SOLUTIONS
Cookistador
Memorable Member
Memorable Member

Hi @martinnilsson 

 

It is possible, this is how to achieve that

 

  • Select one of your tables (it doesn't matter which one).
  • Go to the "Home" tab in the Power Query Editor ribbon.
  • Click on the "Merge Queries" dropdown and select "Merge Queries as New" (recommended to keep your original tables intact) or "Merge Queries" (if you want to modify the existing table).
  • A "Merge" dialog box will appear.
  • Select the Primary Table: The table you selected in the previous step will be at the top.
  • Select the Secondary Table: Use the dropdown below to select the other table you want to join (either "Sales data table" or "Open Orders table").
  • Select Matching Columns:
    • In both tables, select the columns that form the join keys. Based on your description, these are: Division, Year, Month, BU, PG, Cust no, and Item no.
    • Click on each of these column names in both table previews while holding down the Ctrl key to select multiple columns. The order in which you select them matters. Power Query will try to match them based on the selection order 
    • The dialog box will display the number of matching rows.
    • Below the table previews, you'll see a dropdown for "Join Kind". You need to choose the appropriate join type based on your requirements$

 

  • After clicking "OK", a new column will be added to your first table. This column will contain nested tables from the second table (for the matching rows). The column header will likely be the name of your second table.
  • Click on the double-headed arrow (Expand icon) in the header of this new column.

 

While merging the tables directly will work, it's not the most optimal approach for a well-performing Power BI model. Ideally, you should restructure your data into fact and dimension tables. If that's not immediately possible, consider creating a single combined key column from your join fields in both tables. For better performance during the join, aim to represent this combined key as a number if feasible, rather than text.

 

View solution in original post

v-venuppu
Community Support
Community Support

Hi @martinnilsson ,

Thank you for reaching out to Microsoft Fabric Community.

You can achieve the join of your sales data and open orders data within Power Query. Here's some steps to achieve it:

  • First, load both your sales data and open orders data into Power BI and click on "Transform Data" which will redirect you to Power Query.
  • In Power Query, use the "Merge Queries" feature to join the two tables. You can find this option in the "Home" tab.
  • Select the sales data table as your primary table and the open orders data table as your secondary table.
  • Choose the columns you want to use as keys for the join. In your case, you would select Division, Year, Month, BU, PG, Cust no, and Item no from both tables.
  • Choose the type of join you want to perform. For your requirement, a "Left Outer Join" would be appropriate, as it will include all rows from the sales data table and match rows from the open orders table.
  • After merging, you will need to expand the columns from the open orders table to include Qty_on_order and Value in your result table. You can do this by clicking on the expand icon next to the merged column and selecting the columns you want to include.

Please go through the attached files for your reference.

 

RamaU_1-1744263844793.png

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Regards,

Rama U.

View solution in original post

2 REPLIES 2
v-venuppu
Community Support
Community Support

Hi @martinnilsson ,

Thank you for reaching out to Microsoft Fabric Community.

You can achieve the join of your sales data and open orders data within Power Query. Here's some steps to achieve it:

  • First, load both your sales data and open orders data into Power BI and click on "Transform Data" which will redirect you to Power Query.
  • In Power Query, use the "Merge Queries" feature to join the two tables. You can find this option in the "Home" tab.
  • Select the sales data table as your primary table and the open orders data table as your secondary table.
  • Choose the columns you want to use as keys for the join. In your case, you would select Division, Year, Month, BU, PG, Cust no, and Item no from both tables.
  • Choose the type of join you want to perform. For your requirement, a "Left Outer Join" would be appropriate, as it will include all rows from the sales data table and match rows from the open orders table.
  • After merging, you will need to expand the columns from the open orders table to include Qty_on_order and Value in your result table. You can do this by clicking on the expand icon next to the merged column and selecting the columns you want to include.

Please go through the attached files for your reference.

 

RamaU_1-1744263844793.png

 

If this post helps, then please consider Accepting as solution to help the other members find it more quickly, don't forget to give a "Kudos" – I’d truly appreciate it! 

 

Regards,

Rama U.

Cookistador
Memorable Member
Memorable Member

Hi @martinnilsson 

 

It is possible, this is how to achieve that

 

  • Select one of your tables (it doesn't matter which one).
  • Go to the "Home" tab in the Power Query Editor ribbon.
  • Click on the "Merge Queries" dropdown and select "Merge Queries as New" (recommended to keep your original tables intact) or "Merge Queries" (if you want to modify the existing table).
  • A "Merge" dialog box will appear.
  • Select the Primary Table: The table you selected in the previous step will be at the top.
  • Select the Secondary Table: Use the dropdown below to select the other table you want to join (either "Sales data table" or "Open Orders table").
  • Select Matching Columns:
    • In both tables, select the columns that form the join keys. Based on your description, these are: Division, Year, Month, BU, PG, Cust no, and Item no.
    • Click on each of these column names in both table previews while holding down the Ctrl key to select multiple columns. The order in which you select them matters. Power Query will try to match them based on the selection order 
    • The dialog box will display the number of matching rows.
    • Below the table previews, you'll see a dropdown for "Join Kind". You need to choose the appropriate join type based on your requirements$

 

  • After clicking "OK", a new column will be added to your first table. This column will contain nested tables from the second table (for the matching rows). The column header will likely be the name of your second table.
  • Click on the double-headed arrow (Expand icon) in the header of this new column.

 

While merging the tables directly will work, it's not the most optimal approach for a well-performing Power BI model. Ideally, you should restructure your data into fact and dimension tables. If that's not immediately possible, consider creating a single combined key column from your join fields in both tables. For better performance during the join, aim to represent this combined key as a number if feasible, rather than text.

 

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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