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
HI
I am running into an issue understanding the variables behavior. Once i use a var to make my formula more dynamic, the totals are screwed up
BASE:
usage = SUMX ( fact_bom, fact_bom[TotalQty]* [m_fcst_qty_erp] )
Now I want to introduce a base measure, to change the source of the calculation
usage dynamic=
var _base = [m_fcst_qty_erp]
var _res = SUMX ( fact_bom, fact_bom[TotalQty]* _base )
return
_resthe dynamic version gives me the correct values on row level, but totals are wrong
I understand the vars are only calculated once, but I thought onces per calculation, meaning rows or totals, or where ever a result is calculated.
I do not have a sample file, but its more an understanding problem of some basics.
Hope someone can lighten me up
thanks
Solved! Go to Solution.
Variables are calculated once per row context in SUMX, not once per entire measure. Your issue is that [m_fcst_qty_erp] is being evaluated outside the row context.
Fix it by moving the variable inside SUMX:
usage dynamic =
SUMX(
fact_bom,
VAR _base = [m_fcst_qty_erp]
RETURN
fact_bom[TotalQty] * _base
)
Variables are calculated once per row context in SUMX, not once per entire measure. Your issue is that [m_fcst_qty_erp] is being evaluated outside the row context.
Fix it by moving the variable inside SUMX:
usage dynamic =
SUMX(
fact_bom,
VAR _base = [m_fcst_qty_erp]
RETURN
fact_bom[TotalQty] * _base
)
Hi @Hansolu ,
Thanks for reaching out to the Microsoft fabric community forum.
I would also take a moment to thank @Kedar_Pande , for actively participating in the community forum and for the solutions you’ve been sharing in the community forum. Your contributions make a real difference.
I hope the below details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We’re always here to support you
Best Regards,
Community Support Team
Hi @Hansolu ,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We’re always here to support you.
Best Regards,
Community Support Team
Hi @Hansolu ,
I hope the above details help you fix the issue. If you still have any questions or need more help, feel free to reach out. We’re always here to support you.
Best Regards,
Community Support Team
Hi,
I tried to create a table to briefly explain how two measures work.
Please check the below picture, and I hope it helps.
Because, VAR is calculated once inside the measure, when it comes to the total row context, VAR is calcualted as 27.
HI
thanks for the explanation, however i am still confused.
I thought SUMX is kind of store the row results and at the total level it is summing up all stored results.
In my simple example, I can not use var for one element of the calculation inside the sumx as the total would be always wrong?
The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!
| User | Count |
|---|---|
| 40 | |
| 37 | |
| 33 | |
| 29 | |
| 27 |
| User | Count |
|---|---|
| 134 | |
| 104 | |
| 63 | |
| 60 | |
| 55 |