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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
PeteSmith6730
Frequent Visitor

DAX issue with variable referring to another measure not adjusting filter context in returned switch

I am coming (hopefully!) to the end of writing a pbix to handle management accounting for a large multidept business and am trying to make use of variables to speed up the DAX

 

However, if I create a variable referring to a measure which has a filter statement in it and then in the return statement try to further apply the filter it does not action the variable as intended.

Extract of problem below:
Measure MAarg1 = CALCULATE([MASum], filter(all(MAReports),MAReports[AccountKey]=max(MAReports[MAKPI_Arg1])))


Then in another measure reference the above via a variable
Var vMAArg1 = [MAArg1]
Return
Switch([MAKPI],
blah, blahresult,
blah2, blah2result,
 "Filter11", calculate(vMAArg1,FILTER(All(OperationCodes),OperationCodes[DeptCode]=11)),
Etcetera)

The above does not perform the dept code filter, but returns an unfiltered result.
However if I replace vMAArg1 with a reference to the original measure [MAArg1] all is good!

it would be good to get this to work since the switch statement is quite large and the use of variables in other areas of the problem measure have given significant performance gains.
I think the problem lies in the fact that there are 2 filter contexts going on, but not really sure.

Look forward to hearing from you
Pete

2 REPLIES 2
Anonymous
Not applicable

By the way... If you are filtering a fact table directly (and this can be seen in your code) instead of using dimensions only to slice and dice, then the design is flawed and you'll be very likely getting wrong numbers without even realizing it.

You've been warned.

Best
D
Anonymous
Not applicable

Variables referring to values are calculated at the time of declaration and are static. Only table variables can be filtered. Also, variables cannot be re-assigned.

Best
D

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.