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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Assadujaman
Regular Visitor

DAX help

Data table 1

DepartmentTotal Union and NOn-Union 2020Total Union and NOn-Union 2021Number of Union 2020Number of Union 2021Number of Non-Union 2020Number of Non-Union 2021Number of Leaders in 2020Number of Leaders in 2021
Sales42412022221956
Finance35361515202133

Data table 2

EE IDTermination ReasonEffective date YearEE TypeDepartment Leader/ No Leader    
XXXA2020UnionSalesLeader    
ZZZB2021Non-UnionSalesLeader    
YYYA2021Non-UnionFinanceNo Leader    

 

 

I wanted to create a table like this.

 

Department 2020 2021 
SalesTotal Termination reason if A / (Total Union + non Union)  

Total Termination reason if A / (Total Union + non Union)  

 

 
Finance   
    

 

 

Department 2020 2021 
SalesTotal Termination of leader / (Count of leader)  

SalesTotal Termination of leader / (Count of leader)  

 

 
Finance   
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Assadujaman ,

 

Here are the steps you can follow:

1. In Power Query – Check the rest of the columns except [Department].

vyangliumsft_0-1677824311293.png

 

Result:

vyangliumsft_1-1677824267302.png

2. Create calculated table.

True =
VAR _Department2020 =
    MAXX (
        FILTER (
            ALL ( Table2 ),
            'Table2'[Termination Reason] = "A"
                && 'Table2'[Effective date Year] = 2020
        ),
        'Table2'[Department]
    )
VAR _Department2021 =
    MAXX (
        FILTER (
            ALL ( Table2 ),
            'Table2'[Termination Reason] = "A"
                && 'Table2'[Effective date Year] = 2021
        ),
        'Table2'[Department]
    )
RETURN
    SUMMARIZE (
        'Table1',
        'Table1'[Department],
        "2020",
            IF (
                [Department] = _Department2020,
                SUMX (
                    FILTER (
                        ALL ( Table1 ),
                        VALUE ( RIGHT ( 'Table1'[Attribute], 4 ) ) = 2020
                            && 'Table1'[Department] = EARLIER ( [Department] )
                            && CONTAINSSTRING ( 'Table1'[Attribute], "Total Union and NOn-Union" ) = TRUE ()
                    ),
                    [Value]
                )
            ),
        "2021",
            IF (
                [Department] = _Department2021,
                SUMX (
                    FILTER (
                        ALL ( Table1 ),
                        VALUE ( RIGHT ( 'Table1'[Attribute], 4 ) ) = 2021
                            && 'Table1'[Department] = EARLIER ( [Department] )
                            && CONTAINSSTRING ( 'Table1'[Attribute], "Total Union and NOn-Union" ) = TRUE ()
                    ),
                    [Value]
                )
            )
    )

3. Result:

vyangliumsft_2-1677824267303.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

2 REPLIES 2
Anonymous
Not applicable

Hi  @Assadujaman ,

 

Here are the steps you can follow:

1. In Power Query – Check the rest of the columns except [Department].

vyangliumsft_0-1677824311293.png

 

Result:

vyangliumsft_1-1677824267302.png

2. Create calculated table.

True =
VAR _Department2020 =
    MAXX (
        FILTER (
            ALL ( Table2 ),
            'Table2'[Termination Reason] = "A"
                && 'Table2'[Effective date Year] = 2020
        ),
        'Table2'[Department]
    )
VAR _Department2021 =
    MAXX (
        FILTER (
            ALL ( Table2 ),
            'Table2'[Termination Reason] = "A"
                && 'Table2'[Effective date Year] = 2021
        ),
        'Table2'[Department]
    )
RETURN
    SUMMARIZE (
        'Table1',
        'Table1'[Department],
        "2020",
            IF (
                [Department] = _Department2020,
                SUMX (
                    FILTER (
                        ALL ( Table1 ),
                        VALUE ( RIGHT ( 'Table1'[Attribute], 4 ) ) = 2020
                            && 'Table1'[Department] = EARLIER ( [Department] )
                            && CONTAINSSTRING ( 'Table1'[Attribute], "Total Union and NOn-Union" ) = TRUE ()
                    ),
                    [Value]
                )
            ),
        "2021",
            IF (
                [Department] = _Department2021,
                SUMX (
                    FILTER (
                        ALL ( Table1 ),
                        VALUE ( RIGHT ( 'Table1'[Attribute], 4 ) ) = 2021
                            && 'Table1'[Department] = EARLIER ( [Department] )
                            && CONTAINSSTRING ( 'Table1'[Attribute], "Total Union and NOn-Union" ) = TRUE ()
                    ),
                    [Value]
                )
            )
    )

3. Result:

vyangliumsft_2-1677824267303.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

lbendlin
Super User
Super User

That's not really a DAX question.  You will want to consider bringing your source table into a format that can be used by Power BI. You can try unpivoting in Power Query but that would have to be done in pairs.

 

Department Year Union Non-Union Leaders

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

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 community update carousel

Fabric Community Update - June 2025

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