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
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
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.