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

Get inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.

Reply
w_Das
Frequent Visitor

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

Hi @w_Das 

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

Hi @w_Das 

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

@w_Das 
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
)
)

Hi @johnbasha33 ,

Thanks for the reply,

Table A and B have  name only 

Table A = VALUES(TableName[Month)


Thanks,
w_D

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 FABINSIDER for a $400 discount!

FebPBI_Carousel

Power BI Monthly Update - February 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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