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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
DFC
Frequent Visitor

Make Subtotal use Average instead of Sum

Hi

 

I need to compute a weighted average and while each row of the matrix is following the DAX i created, the subtotal for each group is doing some sort of sum. Not only do i not understand what sum it is doing but what i want is the Average of each entry in the group.

 

The general idea is to get the full year of the budgetted availability weighted by the number of days in each month. This value should be the same regardless of the month picked in slicers, it isn't a YTD sort of year. The DAX is the following:

 

 

FullYear = 
        var MultSum = CALCULATE(SUMX('Sheet1', ([Availability])*[Days of the month]), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

    var SumDays = CALCULATE(COUNTROWS('Calendar Table'), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

    return  MultSum / SumDays

 

 

I recreated my issue in a simple example. I would post the files but i can figure out how to import them here. Essentially, for the "one Letter" group, the "FullYear" value should have been 95.94%.

 

 

Report & Data examples:

[Snapshots]

DFC_1-1615490480364.png

 

DFC_0-1615490445087.png

 

 

 

 

 

 

 

1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@DFC This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

Also, you may find this helpful as well:

Matrix Measure Total Triple Threat Rock & Roll - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Greg_Deckler
Super User
Super User

@DFC This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

 

Also, you may find this helpful as well:

Matrix Measure Total Triple Threat Rock & Roll - Microsoft Power BI Community


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

I followed your suggestion, @Greg_Deckler,  of the IF( HASONEFILTER(...)) and it worked. However, I feel like i just "hammered" the right answer onto the report when there's probably a better DAX to be used. Could you correct my DAX especially for the case where HASONEFILTER is false.

FullYear_subtot = 
        var MultSum = CALCULATE(SUMX('Sheet1', ([Availability])*[Days of the month]), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

        var SumDays = CALCULATE(COUNTROWS('Calendar Table'), ALL('Calendar Table'), VALUES('Calendar Table'[Year]))

        return IF(
                    HASONEFILTER(Sheet1[Type]),
                    MultSum / SumDays,
                    CALCULATE(SUMX('Sheet1', ([Availability])*[Days of the month]), ALL('Sheet1'), VALUES('Sheet1'[Group]), VALUES('Calendar Table'[Year])) / (SumDays * CALCULATE(DISTINCTCOUNT(Sheet1[Type]), VALUES(Sheet1[Group])))
                    )

 

 I would accept your answer as the correct one immediately but im not sure if that wont shut down the whole thread and Id like to have some feedback from you.

 

Thank you for pointing me tot he right direction.

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

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

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors