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
Nicpet0
Regular Visitor

issues with RETURN statement from variables

Hi Community

im trying to create a DAX calculation that evaluates invoiced quantity based on my "Selection" variable. My issue is the return statement, where it wont divide my number with 1000 which i use to convert from kg to tonnes. How can i change my code to. Any tips for the overall structure of my code will also be helpful. 

Se snippet below for context. 

Thank you! 


Nicpet0_1-1757419746946.png

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

I don't think that this is calculating what you want it to. The Total, Selection and External variables will not be recalculated for each iteration of Company Name. In DAX variables are not really variable, they are constants which are only calculated once.

If you wish to recalculate for each company then you would need to move the variables inside the SUMX.

View solution in original post

6 REPLIES 6
v-lgarikapat
Community Support
Community Support

Hi @Nicpet0 ,

Thanks for reaching out to the Microsoft fabric community forum.

@johnt75 , @bhanu_gautam , 

Thanks for your prompt response

@Nicpet0 

 wanted to follow up and confirm whether you’ve had the opportunity to review the information  provided by  @johnt75 , @bhanu_gautam  . If you have any questions or need further clarification, please don’t hesitate to reach out.

 

We appreciate your collaboration and support!

Best regards,
Lakshmi.

Hi @Nicpet0 ,

 

We’d like to confirm whether your issue has been successfully resolved. If you still have any questions or need further assistance, please don’t hesitate to reach out. We’re more than happy to continue supporting you.

We appreciate your engagement and thank you for being an active part of the community.


Best Regards,
Lakshmi.

Hi @Nicpet0 ,

 

We’d like to confirm whether your issue has been successfully resolved. If you still have any questions or need further assistance, please don’t hesitate to reach out. We’re more than happy to continue supporting you.

We appreciate your engagement and thank you for being an active part of the community.


Best Regards,
Lakshmi.

johnt75
Super User
Super User

I don't think that this is calculating what you want it to. The Total, Selection and External variables will not be recalculated for each iteration of Company Name. In DAX variables are not really variable, they are constants which are only calculated once.

If you wish to recalculate for each company then you would need to move the variables inside the SUMX.

bhanu_gautam
Super User
Super User

@Nicpet0 , Try using

 

VAR Total =
CALCULATE(
[Invoiced Quantity (Base) LYTD],
KEEPFILTERS(
Customer[Customer Posting Group] IN {"Group", "Group_SBU", "Retail", "Wholesale", "Grower"}
)
)

VAR External =
CALCULATE(
[Invoiced Quantity (Base) LYTD],
KEEPFILTERS(
Customer[Customer Posting Group] IN {"Retail", "Wholesale", "Grower"}
)
)

VAR Selection =
IF(
SELECTEDVALUE('Type of Sales'[Intercompany Sales]) = "On",
Total,
External
)

RETURN
SUMX(
VALUES('Company'[Company Name]),
IF(
'Company'[Company Name] = "", // Ensure this condition is correct
(Selection * 0.45359) / 1000,
Selection / 1000
)
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Thanks your input

Yes the condition is correct. Nothing changes for me, since the code is the exact same as before

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.