Forum Discussion
Best Approach to Two Dax Challenges?
- 8 years ago
Hi,
Let's solve the first one. Try this
=(CALCULATE(SUM(ConsumptionData2017[Gal (000s)]),ConsumptionData2017[Rate Class]="Residential")/CALCULATE(DISTINCTCOUNT(ConsumptionData2017[Location ID]),ConsumptionData2017[Rate Class]="Residential"))/12
Does this work?
- Anonymous8 years ago
Looks like you're missing a DIVIDE() statement in the first parameter of your CALCULATE() ...
Test Dax := CALCULATE ( DIVIDE ( AVERAGE ( ConsumptionData2017[Gal (000s)] ), DISTINCTCOUNT ( ConsumptionData2017[Location ID] ) ), ConsumptionData2017[Rate Class] = "Residential" )PS...go to www.daxformatter.com to get the nicely formatted code that I've been providing. It's a HUGE help, especially with more complex DAX.
Regarding wanting to see the monthly average in the grand total, you may want to use the following pattern:
IF(
HASONEVALUE( Month ),
[Subtotal measure for 1 month],
[Different measure for calculating in the grand total]
)
There's some good documentation on this already. Check PowerPivotPro's website.
Hi,
Let's solve the first one. Try this
=(CALCULATE(SUM(ConsumptionData2017[Gal (000s)]),ConsumptionData2017[Rate Class]="Residential")/CALCULATE(DISTINCTCOUNT(ConsumptionData2017[Location ID]),ConsumptionData2017[Rate Class]="Residential"))/12
Does this work?
Ashish_Mathur I forgot to divide by 12 as you did, good catch!
=
CALCULATE (
DIVIDE (
SUM ( ConsumptionData2017[Gal (000s)] ),
DISTINCTCOUNT ( ConsumptionData2017[Location ID] )
),
ConsumptionData2017[Rate Class] = "Residential"
)
/ 12I think you can combine the arithmetic steps into 1 calculate statement to force the right filter context. And using DIVIDE() will catch division by zero errors.