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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

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
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.