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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Dax to make a table ready for matrix graphs in power bi

Hi,

 

I have a table as below: 

Org1Org2Dept1Dept2
O1O2Dept1.1Dept2.1
O1O3Dept1.2Dept2.2
 O2Dept1.3Dept2.3
O1O2Dept1.4Dept2.4
O1 Dept1.5Dept2.5

 

I need to create a hierarchy table as below to create a matrix graph in power bi. 

L1L2L3
O1Dept1Dept1.1
O1Dept1Dept1.2
O1Dept1Dept1.4
O1Dept1Dept1.5
O1Dept2Dept2.1
O1Dept2Dept2.2
O1Dept2Dept2.4
O1Dept2Dept2.5
O2Dept1Dept1.1
O2Dept1Dept1.3
O2Dept1Dept1.4
O2Dept2Dept2.1
O2Dept2Dept2.3
O2Dept2Dept2.4
O3Dept1Dept1.2
O3Dept2Dept2.2

 
Any quick help would be appreciated.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

If you can transform your data in power query editor, you can try to duplicate you data table ,then use append and unpivot function to achieve your goal. Or you can build a calculated table by dax.

Dax:

 

Dax = 
VAR _O1 =
    SUMMARIZE (
        FILTER ( 'Data Table', 'Data Table'[Org1] <> BLANK () ),
        'Data Table'[Org1],
        'Data Table'[Dept1],
        'Data Table'[Dept2]
    )
VAR _O2 =
    SUMMARIZE (
        FILTER ( 'Data Table', 'Data Table'[Org2] <> BLANK () ),
        'Data Table'[Org2],
        'Data Table'[Dept1],
        'Data Table'[Dept2]
    )
RETURN
    VAR _T =
        UNION ( _O1, _O2 )
    RETURN
        UNION (
            SUMMARIZE ( _T, [Org1], [Dept1], "L2", "Dept1" ),
            SUMMARIZE ( _T, [Org1], [Dept2], "L2", "Dept2" )
        )

 

Result is as below.

1.png

Power Query Editor:

Duplicate Data Table twice and rename them as O1(Remove Org2 in this table)/O2 (Remove Org1 in this table)

Append them as a new table named Append1.

Unpivot Dept1 and Dept2, rename the columns as L1,L2,L3, and sort the columns by ascending.

Result is as below.

3.png

 You can download the pbix file from this link: Dax to make a table ready for matrix graphs in power bi

 

Best Regards,

Rico Zhou

 

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

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous 

If you can transform your data in power query editor, you can try to duplicate you data table ,then use append and unpivot function to achieve your goal. Or you can build a calculated table by dax.

Dax:

 

Dax = 
VAR _O1 =
    SUMMARIZE (
        FILTER ( 'Data Table', 'Data Table'[Org1] <> BLANK () ),
        'Data Table'[Org1],
        'Data Table'[Dept1],
        'Data Table'[Dept2]
    )
VAR _O2 =
    SUMMARIZE (
        FILTER ( 'Data Table', 'Data Table'[Org2] <> BLANK () ),
        'Data Table'[Org2],
        'Data Table'[Dept1],
        'Data Table'[Dept2]
    )
RETURN
    VAR _T =
        UNION ( _O1, _O2 )
    RETURN
        UNION (
            SUMMARIZE ( _T, [Org1], [Dept1], "L2", "Dept1" ),
            SUMMARIZE ( _T, [Org1], [Dept2], "L2", "Dept2" )
        )

 

Result is as below.

1.png

Power Query Editor:

Duplicate Data Table twice and rename them as O1(Remove Org2 in this table)/O2 (Remove Org1 in this table)

Append them as a new table named Append1.

Unpivot Dept1 and Dept2, rename the columns as L1,L2,L3, and sort the columns by ascending.

Result is as below.

3.png

 You can download the pbix file from this link: Dax to make a table ready for matrix graphs in power bi

 

Best Regards,

Rico Zhou

 

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

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.

Top Solution Authors
Top Kudoed Authors