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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
RPAI2812
Helper I
Helper I

Compare different years measures with a month slice

My database consists of monthly emissions data from three different years (2020, 2019 and 2018).

I've created three measures to filter the total emissions for each year a forth to compare emissions between 2020 and 2018: 

Total 2018 = CALCULATE(Emissions,YEAR('Date'[Date])=2018)
Total 2019 = CALCULATE(Emissions,YEAR('Date'[Date])=2019)

Total 2020 = CALCULATE(Emissions,YEAR('Date'[Date])=2020)

Var 2020-2018= [Total 2020] - [Total 2018].
However, I want to have be able to add a month slicer to my dashboard. That is, I want to be able to compare for instance 2020 and 2018 on Jan + Feb + Mar, or any other months combination that I select. But, when I do so and select the months on this slicer, the result from any of these 4 measures does not change. All I can get is the full year comparison.

 

1 ACCEPTED SOLUTION
AlexisOlson
Super User
Super User

The conditions within CALCULATE remove and replace the existing filter context, so slicing on month doesn't change anything since that filter gets replaced.

 

Try wrapping the conditions with KEEPFILTERS to preserve existing filters.

Total 2018 = CALCULATE ( Emissions, KEEPFILTERS ( YEAR ( 'Date'[Date] ) = 2018 ) )

View solution in original post

2 REPLIES 2
AlexisOlson
Super User
Super User

The conditions within CALCULATE remove and replace the existing filter context, so slicing on month doesn't change anything since that filter gets replaced.

 

Try wrapping the conditions with KEEPFILTERS to preserve existing filters.

Total 2018 = CALCULATE ( Emissions, KEEPFILTERS ( YEAR ( 'Date'[Date] ) = 2018 ) )

It worked perfectly! 

Thank you very much!

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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