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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Nicpet0
New Contributor II

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
Esteemed Contributor III

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
bhanu_gautam
Honored Contributor III

@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

johnt75
Esteemed Contributor III

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.

v-lgarikapat
Valued Contributor III

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.

v-lgarikapat
Valued Contributor III

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.

v-lgarikapat
Valued Contributor III

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.

Helpful resources

Announcements
Users online (25)