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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

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

August Carousel

Fabric Community Update - August 2024

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