Forum Discussion
DAX
In the first measure, I'm trying to compute the average quarterly sales and next measure the average montly sales in each year. In the first mesure, i should be getting the year level value in the quarter level as well since there is an ALL function around the quarter column, but why am i getting this result. Same issue with the second measure. Any reason why this is happening
Hi Cyriackpazhe,
Thank you for reaching out to the Microsoft fabric community forum. Thank you some_bih, for your inputs on this issue.
Thank you for bringing this to my attention. Upon reviewing your DAX measures, I noticed the inconsistency in average quarterly and monthly sales across different periods, even with the ALL() function applied.
This occurs because ALL('Calendar'[Quarter]) or ALL('Calendar'[Month]) only removes the filter for that specific column. However, in a matrix visual with a hierarchy (such as Year > Quarter or Year > Month), the row-level filters from the visual still affect the context, resulting in varying outcomes for each row.
To ensure the calculation is performed at the year level and the same value is displayed across quarters or months in the matrix, you can use the following DAX measures with ALLEXCEPT, which retains only the Year filter:
Quarterly Average:
DAX CopyEdit Quarterly Average = CALCULATE ( AVERAGEX ( VALUES ( 'Calendar'[Quarter] ), [Total Sales] ), ALLEXCEPT ( 'Calendar', 'Calendar'[Year] ) )Monthly Average:
DAX CopyEdit Monthly Average = CALCULATE ( AVERAGEX ( VALUES ( 'Calendar'[Month] ), [Total Sales] ), ALLEXCEPT ( 'Calendar', 'Calendar'[Year] ) )ALLEXCEPT clears all filters from the Calendar table except for Year, so the average is always calculated at the year level just as intended. This approach avoids row context interference from the visual (like month or quarter rows).
If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.
Thank you for using Microsoft Community Forum.
7 Replies
- v-kpoloju-msft
Community Support
Hi Cyriackpazhe,
Thank you for reaching out to the Microsoft fabric community forum. Thank you some_bih, for your inputs on this issue.
Thank you for bringing this to my attention. Upon reviewing your DAX measures, I noticed the inconsistency in average quarterly and monthly sales across different periods, even with the ALL() function applied.
This occurs because ALL('Calendar'[Quarter]) or ALL('Calendar'[Month]) only removes the filter for that specific column. However, in a matrix visual with a hierarchy (such as Year > Quarter or Year > Month), the row-level filters from the visual still affect the context, resulting in varying outcomes for each row.
To ensure the calculation is performed at the year level and the same value is displayed across quarters or months in the matrix, you can use the following DAX measures with ALLEXCEPT, which retains only the Year filter:
Quarterly Average:
DAX CopyEdit Quarterly Average = CALCULATE ( AVERAGEX ( VALUES ( 'Calendar'[Quarter] ), [Total Sales] ), ALLEXCEPT ( 'Calendar', 'Calendar'[Year] ) )Monthly Average:
DAX CopyEdit Monthly Average = CALCULATE ( AVERAGEX ( VALUES ( 'Calendar'[Month] ), [Total Sales] ), ALLEXCEPT ( 'Calendar', 'Calendar'[Year] ) )ALLEXCEPT clears all filters from the Calendar table except for Year, so the average is always calculated at the year level just as intended. This approach avoids row context interference from the visual (like month or quarter rows).
If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.
Thank you for using Microsoft Community Forum.- v-kpoloju-msft
Community Support
Hi Cyriackpazhe,
May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.
Thank you.- v-kpoloju-msft
Community Support
Hi Cyriackpazhe,
I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.
- some_bih
Community Champion
Hi Cyriackpazhe try this version for your measure
Quarterly Average Test =
AVERAGEX(
VALUES('Calendar'[Date]),
CALCULATE([Total], ALL('Calendar'[Date]))
)- Cyriackpazhe
Helper III
But what was the error with what i wrote??
It was supposed to give the result as expected right
- some_bih
Community Champion
Hi Cyriackpazhe
measure might aggregate values across all quarters rather than respecting the context of year and quarter