cancel
Showing results 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

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]

1 ACCEPTED SOLUTION
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

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
2 REPLIES 2
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

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Frequent Visitor

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.

Announcements

#### 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.

#### Power BI Monthly Update - February 2024

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

#### Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

#### 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
Top Kudoed Authors