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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

DAX - Matrix Tale Difference - Selected Value (Slicer)

Hi Team,

 

I have created Matric table for FY 24 and 25,26.

and I need difference for the selected month like Table A and Table B, (both are lookup from mail table)

pic.png

 

selected month wise FY difference needed, kindly advise me.

Thanks,

w_D

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous 

Thanks for the solution @johnbasha33  provided, and i want to offer some more information for you to refer to.

Sample data 

vxinruzhumsft_0-1712565145593.png

Table A

vxinruzhumsft_1-1712565162729.png

Table B

vxinruzhumsft_2-1712565193841.png

1.Create a type table

 

Type =
VAR A =
    SUMMARIZE (
        ADDCOLUMNS (
            CROSSJOIN ( VALUES ( 'Table'[Month] ), { "FY24", "FY25", "FY26" } ),
            "Month_FY",
                [Month] & "-" & [Value]
        ),
        [Month_FY]
    )
VAR B = { "Difference-FY24", "Difference-FY25", "Difference-FY26" }
RETURN
    UNION ( A, B )

 

vxinruzhumsft_4-1712565789257.png

2.Create a measure

 

MEASURE =
VAR a =
    LEFT (
        MAX ( 'Type'[Month_FY] ),
        SEARCH ( "-", MAX ( 'Type'[Month_FY] ),, BLANK () ) - 1
    )
RETURN
    IF (
        NOT ( CONTAINSSTRING ( SELECTEDVALUE ( 'Type'[Month_FY] ), "Difference" ) )
            && OR ( a IN VALUES ( 'Table A'[Month] ), a IN VALUES ( 'Table B'[Month] ) ),
        SWITCH (
            TRUE (),
            CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY24" ), CALCULATE ( SUM ( 'Table'[FY24] ), 'Table'[Month] = a ),
            CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY25" ), CALCULATE ( SUM ( 'Table'[FY25] ), 'Table'[Month] = a ),
            CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY26" ), CALCULATE ( SUM ( 'Table'[FY26] ), 'Table'[Month] = a )
        ),
        IF (
            CONTAINSSTRING ( SELECTEDVALUE ( 'Type'[Month_FY] ), "Difference" ),
            SWITCH (
                TRUE (),
                CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY24" ),
                    ABS (
                        CALCULATE (
                            SUM ( 'Table'[FY24] ),
                            'Table'[Month] IN VALUES ( 'Table A'[Month] )
                        )
                            - CALCULATE (
                                SUM ( 'Table'[FY24] ),
                                'Table'[Month] IN VALUES ( 'Table B'[Month] )
                            )
                    ),
                CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY25" ),
                    ABS (
                        CALCULATE (
                            SUM ( 'Table'[FY25] ),
                            'Table'[Month] IN VALUES ( 'Table A'[Month] )
                        )
                            - CALCULATE (
                                SUM ( 'Table'[FY25] ),
                                'Table'[Month] IN VALUES ( 'Table B'[Month] )
                            )
                    ),
                CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY26" ),
                    ABS (
                        CALCULATE (
                            SUM ( 'Table'[FY26] ),
                            'Table'[Month] IN VALUES ( 'Table A'[Month] )
                        )
                            - CALCULATE (
                                SUM ( 'Table'[FY26] ),
                                'Table'[Month] IN VALUES ( 'Table b'[Month] )
                            )
                    )
            )
        )
    )

 

Then put the month-type field in column  and and type field in row and put the measure to the value in the matrix visual.

vxinruzhumsft_5-1712565810137.png

Output

vxinruzhumsft_3-1712565593020.png

 

Best Regards!

Yolo Zhu

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
Anonymous
Not applicable

Hi @Anonymous 

Thanks for the solution @johnbasha33  provided, and i want to offer some more information for you to refer to.

Sample data 

vxinruzhumsft_0-1712565145593.png

Table A

vxinruzhumsft_1-1712565162729.png

Table B

vxinruzhumsft_2-1712565193841.png

1.Create a type table

 

Type =
VAR A =
    SUMMARIZE (
        ADDCOLUMNS (
            CROSSJOIN ( VALUES ( 'Table'[Month] ), { "FY24", "FY25", "FY26" } ),
            "Month_FY",
                [Month] & "-" & [Value]
        ),
        [Month_FY]
    )
VAR B = { "Difference-FY24", "Difference-FY25", "Difference-FY26" }
RETURN
    UNION ( A, B )

 

vxinruzhumsft_4-1712565789257.png

2.Create a measure

 

MEASURE =
VAR a =
    LEFT (
        MAX ( 'Type'[Month_FY] ),
        SEARCH ( "-", MAX ( 'Type'[Month_FY] ),, BLANK () ) - 1
    )
RETURN
    IF (
        NOT ( CONTAINSSTRING ( SELECTEDVALUE ( 'Type'[Month_FY] ), "Difference" ) )
            && OR ( a IN VALUES ( 'Table A'[Month] ), a IN VALUES ( 'Table B'[Month] ) ),
        SWITCH (
            TRUE (),
            CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY24" ), CALCULATE ( SUM ( 'Table'[FY24] ), 'Table'[Month] = a ),
            CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY25" ), CALCULATE ( SUM ( 'Table'[FY25] ), 'Table'[Month] = a ),
            CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY26" ), CALCULATE ( SUM ( 'Table'[FY26] ), 'Table'[Month] = a )
        ),
        IF (
            CONTAINSSTRING ( SELECTEDVALUE ( 'Type'[Month_FY] ), "Difference" ),
            SWITCH (
                TRUE (),
                CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY24" ),
                    ABS (
                        CALCULATE (
                            SUM ( 'Table'[FY24] ),
                            'Table'[Month] IN VALUES ( 'Table A'[Month] )
                        )
                            - CALCULATE (
                                SUM ( 'Table'[FY24] ),
                                'Table'[Month] IN VALUES ( 'Table B'[Month] )
                            )
                    ),
                CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY25" ),
                    ABS (
                        CALCULATE (
                            SUM ( 'Table'[FY25] ),
                            'Table'[Month] IN VALUES ( 'Table A'[Month] )
                        )
                            - CALCULATE (
                                SUM ( 'Table'[FY25] ),
                                'Table'[Month] IN VALUES ( 'Table B'[Month] )
                            )
                    ),
                CONTAINSSTRING ( MAX ( 'Type'[Month_FY] ), "FY26" ),
                    ABS (
                        CALCULATE (
                            SUM ( 'Table'[FY26] ),
                            'Table'[Month] IN VALUES ( 'Table A'[Month] )
                        )
                            - CALCULATE (
                                SUM ( 'Table'[FY26] ),
                                'Table'[Month] IN VALUES ( 'Table b'[Month] )
                            )
                    )
            )
        )
    )

 

Then put the month-type field in column  and and type field in row and put the measure to the value in the matrix visual.

vxinruzhumsft_5-1712565810137.png

Output

vxinruzhumsft_3-1712565593020.png

 

Best Regards!

Yolo Zhu

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

 

johnbasha33
Super User
Super User

@Anonymous 
FYDifference =
VAR SelectedMonth = SELECTEDVALUE(MainTable[Selected Month])
RETURN
CALCULATE(
SUM('Table A'[Value]),
FILTER(
'Table A',
'Table A'[Month] = SelectedMonth
)
) -
CALCULATE(
SUM('Table B'[Value]),
FILTER(
'Table B',
'Table B'[Month] = SelectedMonth
)
)

Anonymous
Not applicable

Hi @johnbasha33 ,

Thanks for the reply,

Table A and B have  name only 

Table A = VALUES(TableName[Month)


Thanks,
w_D

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.