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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
FabiNeed
Helper I
Helper I

Matrix with two different tables with no common key

Hello everyone,

I want to create a matrix in PowerBI based on two tables that do not have a common key and I am grateful for any help/ideas.

 

Table 1 looks like this: 

 

Table1.png

As you can see, it contains a specific hirachy.

 

Table 2 looks like this (excerpt):

 Table2.png

As you can see, each category, subcategory and subsubcategory is a column on its own in Table 2.

 

The goal is to have all the categories, subcategories, and sub-subcategories from Table 1 with their respective hirachie as rows in the matrix, the customers (C1, C2, etc.) in the columns, and the values from Table 2 as the values. The result should look something like this:

 

Picture6345345345.png

I have created a PowerBI file with examplary data: PowerBi file 

 

Does anyone have a good idea how this solution can be archived? Any help is welcome. 🙂

 

Best regards,

Fabi

1 ACCEPTED SOLUTION
v-yangliu-msft
Community Support
Community Support

Hi  @FabiNeed ,

Here are the steps you can follow:

1. Enter the power query, select all columns except [Customer], click Unpivot Columns.

vyangliumsft_0-1654152685332.png

Result:

vyangliumsft_1-1654152649437.png

2. Create measure.

 

Flag =
IF(
  NOT( ISINSCOPE('Table'[Category])&&ISINSCOPE('Table'[Subcategory])) ,
CALCULATE(SUM('Table2'[Value]),FILTER(ALL(Table2),'Table2'[Customer]=MAX('Table2'[Customer])&&'Table2'[Attribute]=MAX('Table'[Category]))),
IF(
ISINSCOPE('Table'[Category]) &&ISINSCOPE('Table'[Subcategory])&&NOT( ISINSCOPE('Table'[Subsubcategory])),
CALCULATE(SUM('Table2'[Value]),FILTER(ALL(Table2),'Table2'[Customer]=MAX('Table2'[Customer])&&'Table2'[Attribute]=MAX('Table'[Subcategory]))),
IF(
ISINSCOPE('Table'[Category]) &&ISINSCOPE('Table'[Subcategory])&&ISINSCOPE('Table'[Subsubcategory]),
CALCULATE(SUM('Table2'[Value]),FILTER(ALL(Table2),'Table2'[Customer]=MAX('Table2'[Customer])&&'Table2'[Attribute]=MAX('Table'[Subsubcategory])))
  ,0)))

 

3. Result:

vyangliumsft_1-1654152749196.png

 

Best Regards,

Liu Yang

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
v-yangliu-msft
Community Support
Community Support

Hi  @FabiNeed ,

Here are the steps you can follow:

1. Enter the power query, select all columns except [Customer], click Unpivot Columns.

vyangliumsft_0-1654152685332.png

Result:

vyangliumsft_1-1654152649437.png

2. Create measure.

 

Flag =
IF(
  NOT( ISINSCOPE('Table'[Category])&&ISINSCOPE('Table'[Subcategory])) ,
CALCULATE(SUM('Table2'[Value]),FILTER(ALL(Table2),'Table2'[Customer]=MAX('Table2'[Customer])&&'Table2'[Attribute]=MAX('Table'[Category]))),
IF(
ISINSCOPE('Table'[Category]) &&ISINSCOPE('Table'[Subcategory])&&NOT( ISINSCOPE('Table'[Subsubcategory])),
CALCULATE(SUM('Table2'[Value]),FILTER(ALL(Table2),'Table2'[Customer]=MAX('Table2'[Customer])&&'Table2'[Attribute]=MAX('Table'[Subcategory]))),
IF(
ISINSCOPE('Table'[Category]) &&ISINSCOPE('Table'[Subcategory])&&ISINSCOPE('Table'[Subsubcategory]),
CALCULATE(SUM('Table2'[Value]),FILTER(ALL(Table2),'Table2'[Customer]=MAX('Table2'[Customer])&&'Table2'[Attribute]=MAX('Table'[Subsubcategory])))
  ,0)))

 

3. Result:

vyangliumsft_1-1654152749196.png

 

Best Regards,

Liu Yang

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

@v-yangliu-msft 

I implemented your solution and it works like a charme. However, I do not really really understand, how the filter part is working. Could you please describe it to me in words using this example: 

 

FILTER(ALL(Table2),'Table2'[Customer]=MAX('Table2'[Customer])&&'Table2'[Attribute]=MAX('Table'[Category]))),

 

Especially the parts with the MAX function are interesting to me since I always thought its only possible to compare integer values.

 

Best,

Fabian

 

This is a perfect solution to the problem. Very well explained. Thank you very much!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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