How to join tables on multiple columns in Power BI Desktop

与世无争的帅哥 提交于 2019-12-04 19:25:16

Short answer is that Power BI doesn't support joining on two columns... but I don't think that is the problem you need to solve here.

Without knowing your full data model, I'm going to make some guesses, but I hope this clears things up for you.

I started with a BudgetData table like this:

and a Premiums table like this:

I used Power BI to create a date table with the following DAX formula.

Dates = CALENDAR(DATE(2017, 1, 1), DATE(2017, 12, 31))

I also used Power BI to create a dimension table for InsurType/Division with the following DAX formula.

InsurTypes = DISTINCT(
    UNION(
        SELECTCOLUMNS(BudgetData, "InsurType", BudgetData[InsurType]),
        SELECTCOLUMNS(Premiums, "InsurType", Premiums[Division])
    )
)

Then I created relationships between the four tables as shown below.

Since you are using a MonthInCalendar column that I don't have, I used the following formulas to create it and a sorting column.

MonthInCalendar = LEFT(Dates[Date].[Month], 3) & " " & Dates[Date].[Year]

MonthInCalendarSort = Dates[Date].[Year] & Dates[Date].[MonthNo]

Then I created a graph configured as shown below, which appears to display the correct information. No relationship between the BudgetData and Premiums tables needed.

You CAN select multiple columns for a merge.

Start by loading both tables (BudgetDate & Premiums) into Power Query.

Then click Home -> Merge Queries -> Merge Queries as New:

Then, in the top section of the Merge window, select 'Premiums' (in the dropdown selector), then click on the 'Division' column header, then press and hold your Ctrl button and click on the 'MonthYear' column header. (You'll see a '1' and a '2' appear beside each column header...make sure they appear in the proper order, i.e., 'Division 1' and 'MonthYear 2').

Then, in the next section of the Merge window, select BudgetDate (in the dropdown selector), then click on the 'InsurType' column header, then press and hold your Ctrl button and click on the 'MonthYear' column header. (You'll see a '1' and a '2' appear beside each column header...make sure they appear in the proper order, i.e., 'InsurType 1' and 'MonthYear 2').

Your Merge window like this:

And when you click OK, you'll get this:

And when you click on this...

in the header of 'NewColumn'... you'll get this:

Clear the check mark beside 'Use original column name as prefix' and click OK to get this:

The create relationship dialog doesn’t allow to select multiple columns So there are 2 workarounds 1. Create a new column on both tables with concatenation InsurType & MonthYear

  1. Power Query can join tables with as many as columns you want.First open Merge Queries from the Combine section of Home tab,You can hold CTRL key and select columns one by one (in the right order of joining).
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!