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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
meehael
Helper II
Helper II

One Measure With Different Calculations Depending on Matrix Row Group Value

Hi everyone,

 

I need to add three extra categories or groups at the bottom of a matrix and do a different calculation for them.

For example, let's say I have a matrix with one category/group "Car Make" and one value which displays a count.

The matrix would look something like this:

Audi10
BMW15
Chrysler20
---TOTAL---45 (Sum of the values above)
---AVERAGE---15 (Average of the values above)
---ETC---Some other calculation

 

"Car Make" populates the matrix dynamically, depending on availability, but the bottom three rows/groups are fixed and need to be displayed always.

 

For this reason, I have created a new table which generates only one column with distinct values for car make, plus I manually added the three rows to that table.

 

I was hoping to create a measure with an IF or SWITCH statement that checks matrix group name and then calculates appropriately, but this obviously doesn't work:

 

 

Measure = CALCULATE(IF(SELECTEDVALUE(CarMakeUnion[name])="---TOTAL---"; SUM(CarMakeUnion[count]); COUNT(CarMakeUnion[name])))

 

 

 

Is it possible to do something like this?

Or should I take a different approach?

I need to have it in only one matrix, however.

 

Any help is appreciated.

 

Thanks and best regards,

Mike

1 ACCEPTED SOLUTION
sturlaws
Resident Rockstar
Resident Rockstar

Hi @meehael 

 

I am a bit confused by your naming of your table, so I created this sample report with some moclup data: pbix 

I have written the measure like

measure = 
VAR _sv =
    CALCULATE ( SELECTEDVALUE ( MatrixRows[MatrixRows] ) )
RETURN
    SWITCH (
        TRUE ();
        _sv = "Total"; CALCULATE ( COUNTROWS ( cars ); ALL ( Cars ) );
        _sv = "Average"; CALCULATE(AVERAGEX ( VALUES ( Cars[CarName] ); CALCULATE(COUNTROWS ( Cars ) ));ALL(Cars));
        _sv = "Other"; BLANK ();
        COUNTROWS ( Cars )
    )

 

Cheers,
Sturla

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

View solution in original post

3 REPLIES 3
sturlaws
Resident Rockstar
Resident Rockstar

Hi @meehael 

 

I am a bit confused by your naming of your table, so I created this sample report with some moclup data: pbix 

I have written the measure like

measure = 
VAR _sv =
    CALCULATE ( SELECTEDVALUE ( MatrixRows[MatrixRows] ) )
RETURN
    SWITCH (
        TRUE ();
        _sv = "Total"; CALCULATE ( COUNTROWS ( cars ); ALL ( Cars ) );
        _sv = "Average"; CALCULATE(AVERAGEX ( VALUES ( Cars[CarName] ); CALCULATE(COUNTROWS ( Cars ) ));ALL(Cars));
        _sv = "Other"; BLANK ();
        COUNTROWS ( Cars )
    )

 

Cheers,
Sturla

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

Thank you @sturlaws !

You gave me an idea which made it work in the end.

 

Best regards,

Mike

Tad17
Solution Sage
Solution Sage

Hey @meehael 

 

You cannot add multiple total rows to a matrix in Power BI. I would suggest sticking the measures on cards beneath the table/matrix.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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