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!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hello,
I have issues with what i think is the order of VAR calculations in my measure.
The code here works:
NDR_WC =
VAR WC_Table =
SUMMARIZE (
Astute_Export,
Astute_Export[EmployeeID],
"TableWC", CALCULATE (
IF (
ISBLANK (
CALCULATE ( SUMX ( Astute_Export, [NDR_WC1] ), Astute_Export[Type] = "Oncost" )
),
CALCULATE ( SUMX ( Astute_Export, [NDR_WC1] ), Astute_Export[Type] = "Payment" ),
CALCULATE ( SUMX ( Astute_Export, [NDR_WC1] ), Astute_Export[Type] = "Oncost" )
)
)
)
RETURN
SUMX ( WC_Table, [TableWC] )
However if i change line 9 CALCULATE function in to a var, for example, it stops working and is giving me the wrong number. How to make this code work?
NDR_WC =
VAR Oncost_WC_Calc =
//Calculates WC existing in OnCost sections
CALCULATE (
SUMX ( Astute_Export, [NDR_Step1] ),
Astute_Export[Type] = "Oncost"
)
VAR Payment_WC_Calc =
//Calculates WC existing in Payment sections
CALCULATE (
SUMX ( Astute_Export, [NDR_Step1] ),
Astute_Export[Type] = "Payment"
)
VAR WC_Table =
SUMMARIZE (
Astute_Export,
Astute_Export[EmployeeID],
"TableWC", IF ( ISBLANK ( Oncost_WC_Calc ), Payment_WC_Calc, Oncost_WC_Calc )
)
RETURN
SUMX ( WC_Table, [TableWC] )
Think about what you want to achieve, and then investigate how your context modifiers may mess with it. VARs help you to avoid some modifiers' impact, but they can also enforce the impact. If you are falmiliar with the EARLIER() function - that's basically what VARs do - they provide you a snapshot of an "earlier" context.
There's a secondary function that VARs fulfill, and it's an ironic one. They help you to avoid calculating the same thing multiple times, and in that respect they are actually constants, not variables. But that part is not overly applicable to your situation.
Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!
Check out the October 2025 Power BI update to learn about new features.
User | Count |
---|---|
12 | |
12 | |
11 | |
10 | |
9 |