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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Variables not working with Calculate

Hi Guys!

 I created the following Variable:

 

EUR =

var summa = SUM(Sheet1[amount])

 

return

 

CALCULATE(summa;Sheet1[currency]="EUR")

 

I want to return the sum of EUR from my list.

The Calculate function does not want to work, it does not want to filter for EUR at all. The result is the same every time (the "summa" what I defined as a variable), no matter what I am filtering for in Calculate. 

 

If I am Calculating the sum of EUR separately with 2 measures, than it works.

 

No idea what is going wrong.

Do you have any advice?

THank you

S.

 

 

 

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi Sturla!

Thank you for your answer.

I have 3 other measure combinations for such calculation. I just wanted to try another way + getting familiar with the concept of variables in dax. That is why I was surprised when I did not get the expected result in the return section of the code.

 

I still not get it why it is so. I believed that the return section was for combining, altering all the variables defined above. 

 

Thank you

S

 

View solution in original post

Yes, the variables are a bit confusing, they are kind of static once they are calculated, so the name variables is a bit counterintuitive

View solution in original post

3 REPLIES 3
sturlaws
Resident Rockstar
Resident Rockstar

Hi, @Anonymous,

 

what you experience is by design. The variable is calculated before the context of the measure, Currency="Eur", is applied.

 

For such a simple measure, there is nothing to gain by using a variable, your measure should be:

 

EUR =
CALCULATE (
    SUM ( Sheet1[amount] );
    FILTER ( SHeet1; Sheet1[currency] = "EUR" )
)

 

 

Cheers,
Sturla

If this post helps, then please consider Accepting it as the solution. Kudos are nice too.

Anonymous
Not applicable

Hi Sturla!

Thank you for your answer.

I have 3 other measure combinations for such calculation. I just wanted to try another way + getting familiar with the concept of variables in dax. That is why I was surprised when I did not get the expected result in the return section of the code.

 

I still not get it why it is so. I believed that the return section was for combining, altering all the variables defined above. 

 

Thank you

S

 

Yes, the variables are a bit confusing, they are kind of static once they are calculated, so the name variables is a bit counterintuitive

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors