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

Customise subtotals in a matrix

I have a matrix below in Power BI and I want to display the subtotal as SUBTRACTION instead of SUM of the values. 

Kanishka001_1-1647261740895.png

I'm using the following measure but it is displaying var b as negative in the grid. Is there a way to show the difference without impacting other values in the grid?

Kanishka001_0-1647261648098.png

 

1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Anonymous , You can use isinscope to replace the subtotals and totals

https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi @Anonymous , 

Please have a try.

Create a table includes Year Fields. 

Table 2 = VALUES('Table'[Year])

Then create a measure.

Measure =
VAR _a =
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER (
            'Table',
            [Portfolio] = "A"
                && [Year] = SELECTEDVALUE ( 'Table 2'[Year] )
        )
    )
VAR _b =
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER (
            'Table',
            [Portfolio] = "B"
                && [Year] = SELECTEDVALUE ( 'Table 2'[Year] )
        )
    )
VAR result =
    CALCULATE (
        MAX ( 'Table'[Sales] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[Portfolio]
                IN VALUES ( 'Table'[Portfolio] )
                    && 'Table'[Year] IN VALUES ( 'Table 2'[Year] )
        )
    )
VAR _answer_ =
    IF ( result <> BLANK (), result, 0 )
RETURN
    IF ( ISINSCOPE ( 'Table'[Portfolio] ), _answer_, _b - _a )

vpollymsft_0-1648025835672.png

 

 

Best Regards

Community Support Team _ Polly

 

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

Anonymous
Not applicable

Hi @Anonymous ,

I have created a simple sample, please refer to it to see if it helps you.

Create a measure.

 

Measure =
VAR _2020 =
    CALCULATE (
        MAX ( 'Table'[VALUE] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[DATE] = 2020
                && 'Table'[subject] = SELECTEDVALUE ( 'Table'[subject] )
        )
    )
VAR _2021 =
    CALCULATE (
        MAX ( 'Table'[VALUE] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[DATE] = 2021
                && 'Table'[subject] = SELECTEDVALUE ( 'Table'[subject] )
        )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[DATE] ), MAX ( 'Table'[VALUE] ), _2020 - _2021 )

 

 

vpollymsft_0-1647500688129.png

vpollymsft_1-1647500699120.png

If I have misunderstood your meaning, please provide your desired output and your pbix without privacy information.

 

Best Regards

Community Support Team _ Polly

 

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

 

Anonymous
Not applicable

Here, we have to display the values of both variables a and b. Also the difference between the two in the subtotals.

Anonymous
Not applicable

Hi @Anonymous , 

Please have a try. 

Create a measure.

Measure = 
VAR _a =
    CALCULATE (
        MAX ( 'Table'[VALUE] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[DATE] = 2020
                && 'Table'[subject] = SELECTEDVALUE ( 'Table'[subject] )
        )
    )
VAR _b =
    CALCULATE (
        MAX ( 'Table'[VALUE] ),
        FILTER (
            ALL ( 'Table' ),
            'Table'[DATE] = 2021
                && 'Table'[subject] = SELECTEDVALUE ( 'Table'[subject] )
        )
    )
RETURN
    IF ( HASONEVALUE ( 'Table'[DATE] ), MAX('Table'[VALUE]),_a&" "& _b&" "  & " "&  (_a-_b))

vpollymsft_0-1648017001951.png

 

 

If I have misunderstood your meaning, please provide your desired output and your pbix without privacy information.

 

Best Regards

Community Support Team _ Polly

 

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

Anonymous
Not applicable

Input data:

Pixie123_1-1648020427170.png

 

Expected Output:

Pixie123_0-1648020375166.png

 

amitchandak
Super User
Super User

@Anonymous , You can use isinscope to replace the subtotals and totals

https://www.kasperonbi.com/use-isinscope-to-get-the-right-hierarchy-level-in-dax/

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Does it not require a hierarchy?

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!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.