Forum Discussion

JL_007's avatar
JL_007
New Member
3 years ago
Solved

Average over filtered table

I'm trying for some time already to get a DAX trick done. It might be very simple, but I'm just not succeeding... I've got this dataset: Year Month Type Value Current 1 A 50 Current ...
  • OwenAuger's avatar
    3 years ago

    Hi JL_007 

    I've attached an example PBIX of what I think you're looking for.

    You can make use of the ALLSELECTED function to restore the "overall" filter context of the visual (for measures displayed directly in the visual).

     

    In my example PBIX, I created these measures:

    Value Sum = 
    SUM ( Data[Value] )
    Current Year Monthly Average = 
    CALCULATE (
        AVERAGEX (
            VALUES ( Data[Month] ),
            [Value Sum]
        ),
        ALLSELECTED (),
        Data[Year] = "Current"
    )

    In Current Year Monthly Average, ALLSELECTED () is applied to restore the overall filter context of the visual, and Year = "Current" is applied as an additional filter. With these filters applied, the monthly average is then calculated using AVERAGEX.

     

    Note that months with no values (where [Value Sum] evaluates to blank) are ignored by AVERAGEX.

    Does something like this work for you?

     

    Regards