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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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

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

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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