Forum Discussion
Two-level aggregation using DAX measures
- 9 years ago
Hi RafalK
You can use nested AVERAGEX functions to get an average of averages.
I'm assuming that if you happen to have multiple rows per Product per Day, you want the Quantity to be summed at a Product/Day level.
(If you can guarantee you will never have multiple rows per Product per Day, you could simplify the below a bit).
Either of these should work:
Average of Averages v1 = AVERAGEX ( VALUES ( YourTable[Product] ), AVERAGEX ( VALUES ( YourTable[Day] ), CALCULATE ( SUM ( YourTable[Quantity] ) ) ) )
Average of Averages v2 =
AVERAGEX (
VALUES ( YourTable[Product] ),
CALCULATE (
AVERAGEX (
VALUES ( YourTable[Day] ),
CALCULATE ( SUM ( YourTable[Quantity] ) )
)
)
)
The second measure avoids redundant iteration over values of the Day column for each Product, with the additional CALCULATE. This could perform better if each Product sells on different sets of Days.
Regards,
Owen :)
Jus check... If P1 is not sold in DAY 1 .. then there are 2 ways to enter in ur data table...
1. To mention value of Quantity as Zero in Day1
2. There is no transaciton in data table of P1 and Day1 ( As no quantity was sold... there wouldn't be any transaction )
Whats ur pattern.. check if the solution works