Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
JL_007
New Member

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:

YearMonthTypeValue
Current1A50
Current1B60
Current2A100
Current3A20
Current4A30
Current5A60
Current6A70
Current7B50
Current7A90
Previous1A100
Previous2B20
Previous3A30
Previous4A60
Previous5A70
Previous6A90
Previous7A50
Previous8A100
Previous9A20
Previous10B30
Previous11A60
Previous11B60
Previous12B70

 

I've got slicers on Month & Type.

 

I would like to have a Line and stacked column chart, where one column represents the current year value per month, the other column the previous year value per month.

The Line should represent the average of values of the current year, taking in to account all the filtering in the slicers. The average is expected to be a horizontal line.

 

I managed to do the columns, but I'm really struggling with the average line.

- CALCULATE always keep taking 'Month' into account, causing my average to be equal to my actual.

- CALCULATETABLE removes the filter context, so it doesn't keep the filter values from the slicers.

 

Any help or suggestions would be appreciated!

Thanks in advance!

 

1 ACCEPTED SOLUTION
OwenAuger
Super User
Super User

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.

OwenAuger_0-1691375629640.png

Does something like this work for you?

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

View solution in original post

2 REPLIES 2
OwenAuger
Super User
Super User

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.

OwenAuger_0-1691375629640.png

Does something like this work for you?

 

Regards


Owen Auger
Did I answer your question? Mark my post as a solution!
Blog
LinkedIn

Well, that's just a perfect solution. Works like a charm!! Thank you, Owen!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.