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
chf
Regular Visitor

Desperate for Help with changing Filter depending on Slicer value

Hi all


Some context: I need to sum some data based on a year slicer. For a big portion of the year, the slicer goes 1-2 years further than there is data in that context (intended). So for example Slicer goes to Year=2022, but there is only data available until 2020.

What I need to do now is Slice the data by year if there is data for that year (normal behaviour), BUT if there isn't, default to the latest year (in this example 2020). I wrote a measure that really should work by my understanding but it simply doesn't, and i can't figure out why:

 

 

 

Total=
VAR Slicer = [SlicerSelectedYear]
VAR DataYear = [AvailableDataYear]
RETURN
IF(
   Slicer <= DataYear,
   SUM(dataTable[ENT]),
   CALCULATE(
      CALCULATE(
         SUM(dataTable[ENT]),
         dataTable[Year] = DataYear
      ),
      ALL(dataTable[Year])
   )
)

 

 


The 2 Variables Slicer and DataYear receive the correct values. The normal behaviour case also works and returns the sum for the selected year. But the alternate case with the Calculate simply returns Blank no matter what I do. My intention behind this code was to first remove the filter on [Year] imposed by the slicer, e.g. 2021, and then filter on [Year] = DataYear, e.g. 2020, instead.


Any help is greatly appreciated.

1 REPLY 1
amitchandak
Super User
Super User

@chf , Try like

 

Total=
VAR Slicer = [SlicerSelectedYear]
VAR DataYear = [AvailableDataYear]
RETURN
IF(
Slicer <= DataYear,
SUM(dataTable[ENT]),
CALCULATE(
SUM(dataTable[ENT]),
Filter(all(dataTable), dataTable[Year] = DataYear)
)
)

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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