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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
tvaishnav
Helper IV
Helper IV

Is there a way to use custom formula for matrix grand total?

I have this matrix,

tvaishnav_0-1654273236639.png

I want to calculate profit in the "Total" line. To do that I need to display cost as a negative number. I was wondering if there is a way where I can write cost and revenue as positive numbers and then use Revenue - Cost to calculate profit and display it in total line?

One way that I can think of doing is to not display total line and create a low that does all the calculate as a part of table itself. I am looking for a better way if there is one.

1 ACCEPTED SOLUTION

MyMeasure =
IF (
    HASONEVALUE ( Dim[lvl1] ),
    SUM ( 'Table'[Value] ),
    CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( Dim, Dim[lvl1] = "revenue" ) )
        - CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( Dim, Dim[lvl1] = "cost" ) )
)

 

sturlaws_0-1654802630152.png

 

change the name here from total to profit:

sturlaws_1-1654802723154.png

 

View solution in original post

5 REPLIES 5
Anonymous
Not applicable

Hi @tvaishnav ,

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

Create a measure.

Measure =
IF (
    ISINSCOPE ( 'Table'[Metric] ),
    IF (
        MAX ( 'Table'[Metric] ) = "Profit",
        (
            SUMX (
                FILTER (
                    ALL ( 'Table' ),
                    'Table'[HENGCOL] = SELECTEDVALUE ( 'Table'[HENGCOL] )
                        && 'Table'[Metric] = "Revenue"
                ),
                'Table'[value]
            )
                - SUMX (
                    FILTER (
                        ALL ( 'Table' ),
                        'Table'[HENGCOL] = SELECTEDVALUE ( 'Table'[HENGCOL] )
                            && 'Table'[Metric] = "Cost"
                    ),
                    'Table'[value]
                )
        ),
        SUM ( 'Table'[value] )
    )
)

vpollymsft_0-1654762017675.png

If I have misunderstood your meaning, please provide more details with your desired output.

 

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.

tvaishnav
Helper IV
Helper IV

Thanks for your response @sturlaws. I thought about this but I don't think this will work. Revenue and cost belong to metric column. I want to change the row total, Profit to be different between Revenue and Cost.

 

tvaishnav_0-1654633851308.png

Profit = Revenue - Cost

 

I do not want to present cost as a negative number. What are my options?

MyMeasure =
IF (
    HASONEVALUE ( Dim[lvl1] ),
    SUM ( 'Table'[Value] ),
    CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( Dim, Dim[lvl1] = "revenue" ) )
        - CALCULATE ( SUM ( 'Table'[Value] ), FILTER ( Dim, Dim[lvl1] = "cost" ) )
)

 

sturlaws_0-1654802630152.png

 

change the name here from total to profit:

sturlaws_1-1654802723154.png

 

tvaishnav
Helper IV
Helper IV

Thank you for your response. I will look into this and update here.

sturlaws
Resident Rockstar
Resident Rockstar

Hi,

 

yes, you can use the hasonevalue()-function in your formulas. 

Assuming that the hiearchy in your matrix is like this: metric_level_1, metric_level_2

rewrite your measure something like this:

EstimateNew = if(hasonevalue(metric_level_1),[revenue]-[Cost],[Estimate])

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 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.

Top Solution Authors
Top Kudoed Authors