Forum Discussion

Cyriackpazhe's avatar
Cyriackpazhe
Helper III
1 year ago
Solved

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 val...
  • v-kpoloju-msft's avatar
    1 year ago

    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.