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
Hansolu
Helper II
Helper II

Understanding variable calculation

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
_res

the 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

1 ACCEPTED SOLUTION
Kedar_Pande
Super User
Super User

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
)

View solution in original post

6 REPLIES 6
Kedar_Pande
Super User
Super User

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 

Jihwan_Kim
Super User
Super User

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.

 

Jihwan_Kim_0-1761543869957.png

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

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?

 

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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.