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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Power BI Matrix Row Calculations

Here is my source data:

 

1.PNG

 

Here is the matrix I am trying to create in Power BI:

 

2.PNG

 

I am running into a few issues such as performing the Count/Sale calculation and assigning different formatting to each individual row.  I can get the Count and Sale columns formatted but I am lost at how to calculat the Count/Sale row.

3.PNG

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

Create this measure to show the result:

avg = 
VAR _sale =
    CALCULATE (
        SUM ( test[Value] ),
        ALLEXCEPT ( 'test', test[Year], test[Region] )
    )
VAR _count =
    CALCULATE (
        SUM ( 'test'[Value] ),
        ALLEXCEPT ( test, test[Year], test[Region] ),
        'test'[Measure] = "Count"
    )
RETURN
    IF (
        ISINSCOPE ( 'test'[Measure] ),
        IF (
            SELECTEDVALUE ( 'test'[Measure] ) = "Count"
                || SELECTEDVALUE ( 'test'[Measure] ) = "Sale",
            SUM ( 'test'[Value] ),
            _sale / _count
        ),
        SUM ( test[Value] ) + _sale / _count
    )

matrix.png

 

Best Regards,
Yingjie Li

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

6 REPLIES 6
v-yingjl
Community Support
Community Support

Hi @Anonymous ,

To achieve this, need to create a new table like this:

avg tab.png

Use union() to combine two tables:

test = UNION('Table','Avg table')

Create a calculated column in 'test' table:

result = 
VAR _sale =
    CALCULATE (
        SUM ( test[Value] ),
        ALLEXCEPT ( 'test', test[Year], test[Region] )
    )
VAR _count =
    CALCULATE (
        SUM ( 'test'[Value] ),
        ALLEXCEPT ( test, test[Year], test[Region] ),
        'test'[Measure] = "Count"
    )
RETURN
    IF (
        'test'[Measure] = "Count"
            || 'test'[Measure] = "Sale",
        'test'[Value],
        _sale / _count
    )

Use a Matrix visual to show the result:

matrix re.png

 

Attached my sample file that hopes to help you, please check and try it: Power BI Matrix Row Calculations.pbix

 

Best Regards,
Yingjie Li

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

Anonymous
Not applicable

I tried using this solution.  One issue in my matrix is I need to show Sales and Count as a SUM, but the Result as an Average.  How could I do this?

 

andrewseaman_0-1595607225777.png

 

Hi @Anonymous ,

Create this measure to show the result:

avg = 
VAR _sale =
    CALCULATE (
        SUM ( test[Value] ),
        ALLEXCEPT ( 'test', test[Year], test[Region] )
    )
VAR _count =
    CALCULATE (
        SUM ( 'test'[Value] ),
        ALLEXCEPT ( test, test[Year], test[Region] ),
        'test'[Measure] = "Count"
    )
RETURN
    IF (
        ISINSCOPE ( 'test'[Measure] ),
        IF (
            SELECTEDVALUE ( 'test'[Measure] ) = "Count"
                || SELECTEDVALUE ( 'test'[Measure] ) = "Sale",
            SUM ( 'test'[Value] ),
            _sale / _count
        ),
        SUM ( test[Value] ) + _sale / _count
    )

matrix.png

 

Best Regards,
Yingjie Li

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

 

Don't use these aggregation functions. Instead create separate measures as I suggested.  Then you can control the behavior both inside the visual and in the totals (via HASONEVALUE() etc)

amitchandak
Super User
Super User

@Anonymous , refer if this can help

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

https://www.sqlbi.com/articles/clever-hierarchy-handling-in-dax/

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
lbendlin
Super User
Super User

when you add your measures to the Values area of the matrix visual you can select the option "show on rows". That will give you the desired outcome even with different data types for your measures.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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