Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more
Hello,
When I use this measure:
Sales Selected Year = CALCULATE(SUM(fSales[Value]), FILTER(ALL(dCalendar), dCalendar[Year] = SELECTEDVALUE(dCalendar[Year]))
It brings all sales from 2018 (considering I did the filter for only that year in a slicer visual). However, if I define:
Selected Year = SELECTEDVALUE(dCalendar[Year])
and then rewrite the expression as:
Sales Selected Year = CALCULATE(SUM(fSales[Value]), FILTER(ALL(dCalendar), dCalendar[Year] = [Selected Year]))
It brings the sales from all years from the dCalendar table, even tought I filtered just the year of 2018 in the page.
How does that happen? Can't I use a value returned in a measure resulted by SELECTEDVALUE function to pass as a filter?
*There is a date relationship between fSales and dCalendar.
Thanks.
Solved! Go to Solution.
Welcome to the fun world of DAX filter context.
The CALCULATE function is quite magical in the way it can create a new filter context for the expression to work with.
If you would like your calculation to work the way you want, please try this.
Sales Selected Year =
VAR x = [Selected Year]
RETURN
CALCULATE(
SUM(fSales[Value]),
FILTER(ALL(dCalendar), dCalendar[Year] = x )
)
Welcome to the fun world of DAX filter context.
The CALCULATE function is quite magical in the way it can create a new filter context for the expression to work with.
If you would like your calculation to work the way you want, please try this.
Sales Selected Year =
VAR x = [Selected Year]
RETURN
CALCULATE(
SUM(fSales[Value]),
FILTER(ALL(dCalendar), dCalendar[Year] = x )
)
Thanks, Phil!
Strangely enough, the calculation is working now in both methods in another computer.
But it is very good to learn this technique, so now I know that sometimes I have to access a measure indirectly using a variable.
Have a good day!
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 41 | |
| 38 | |
| 36 | |
| 30 | |
| 28 |
| User | Count |
|---|---|
| 129 | |
| 88 | |
| 79 | |
| 68 | |
| 63 |