Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
Hi all,
I have a measure that calculates the latest score for a variable (expressed as a percentage) based on the last available date that has data, looking like:
2.8.2. Latest Score =
CALCULATE(
[Gemiddelde beschikbaarheid], FILTER(ALLSELECTED('0 DIM Datum'),'0 DIM Datum'[Date]>=MIN('0 DIM Datum'[Date]) && '0 DIM Datum'[Date]<=MAX('0 DIM Datum'[Date])),FILTER('1 2 Maas koffie details','1 2 Maas koffie details'[Datum] = MAX('1 2 Maas koffie details'[Datum]))).
This measure in a table or card work fine with my date slicer and returns the latest value available in the selected time period.
When I put this in my SWITCH function, it suddenly ignores date context. The SWITCH function looks like:
Most Recent Score =
VAR Mindate = MIN('0 DIM Datum'[Date])
VAR Maxdate = MAX('0 DIM Datum'[Date])
RETURN
SWITCH(
TRUE(),
[2.8.1.], '1 Kwaliteit'[Koppelcode KPI] = "2.8.2.",
FORMAT([2.8.2. Latest Score],"00.0%"),
BLANK() )
I also tried hardcoding the date context in the SWITCH function, but it still ignores the slicer:
/FORMAT(CALCULATE( [Maas Gemiddelde beschikbaarheid],FILTER(ALLSELECTED('0 DIM Datum'),'0 DIM Datum'[Date]>=Mindate && '0 DIM Datum'[Date]<=Maxdate), FILTER('1 2 Maas koffie details','1 2 Maas koffie details'[Datum] = MAX('1 2 Maas koffie details'[Datum]))),"00.0%")
Here's a picture of the measure in the table, with the Debug measures and the slicer around. Outside of the SWITCH-table it shows as 99,6 which is correct, inside it says 99,8 which is the Q2 value.
The problem occurs because the SWITCH function evaluates its conditions before the rest of the measure calculation, the inner CALCULATE in your [2.8.2. Latest Score] measure loses the outer filter context when evaluated inside SWITCH and your date variables (Mindate/Maxdate) are evaluated in a different context than expected
Most Recent Score = VAR Mindate = MIN('0 DIM Datum'[Date]) VAR Maxdate = MAX('0 DIM Datum'[Date]) RETURN SWITCH( TRUE(), [2.8.1.], '1 Kwaliteit'[Koppelcode KPI] = "2.8.2.", FORMAT( CALCULATE( [Gemiddelde beschikbaarheid], KEEPFILTERS('0 DIM Datum'[Date] >= Mindate && '0 DIM Datum'[Date] <= Maxdate), FILTER( '1 2 Maas koffie details', '1 2 Maas koffie details'[Datum] = MAX('1 2 Maas koffie details'[Datum]) ) ), "00.0%" ), BLANK() )
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
81 | |
76 | |
61 | |
37 | |
33 |
User | Count |
---|---|
101 | |
56 | |
51 | |
45 | |
40 |