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

The Power BI Data Visualization World Championships is back! It's time to submit your entry. Live now!

Reply

Problem with variables

Does anybody know why these measure are showing different data? I think it is because the variable doesn't recalculate in the second step.

 

Bedrag PFY =
Var Calculateddmeasure =
    [Bedrag (c)]

Return

IF (
HASONEVALUE ( _Boekperiod[Bedrijf] );
//For Single Company
 
CALCULATE (
Calculateddmeasure;
FILTER (
ALL ( _Boekperiod );
_Boekperiod[Boekjaar]
= SELECTEDVALUE ( _Boekperiod[Boekjaar] ) - 1
&& _Boekperiod[tdboekper_boekper]
= SELECTEDVALUE ( _Boekperiod[tdboekper_boekper] )
&& _Boekperiod[Bedrijf]
=SELECTEDVALUE(_Boekperiod[Bedrijf]))
 
);
//For All Companies (total)

CALCULATE (
Calculateddmeasure;
FILTER (
ALL ( _Boekperiod );
_Boekperiod[Boekjaar]
= SELECTEDVALUE ( _Boekperiod[Boekjaar] ) - 1
&& _Boekperiod[tdboekper_boekper]
= SELECTEDVALUE ( _Boekperiod[tdboekper_boekper] )
)
)
)
 
Bedrag PFY2 =
Var Calculateddmeasure =
    [Bedrag (c)]

Return

IF (
HASONEVALUE ( _Boekperiod[Bedrijf] );
//For Single Company
 
CALCULATE (
[Bedrag (c)];
FILTER (
ALL ( _Boekperiod );
_Boekperiod[Boekjaar]
= SELECTEDVALUE ( _Boekperiod[Boekjaar] ) - 1
&& _Boekperiod[tdboekper_boekper]
= SELECTEDVALUE ( _Boekperiod[tdboekper_boekper] )
&& _Boekperiod[Bedrijf]
=SELECTEDVALUE(_Boekperiod[Bedrijf]))
 
);
//For All Companies (total)

CALCULATE (
[Bedrag (c)];
FILTER (
ALL ( _Boekperiod );
_Boekperiod[Boekjaar]
= SELECTEDVALUE ( _Boekperiod[Boekjaar] ) - 1
&& _Boekperiod[tdboekper_boekper]
= SELECTEDVALUE ( _Boekperiod[tdboekper_boekper] )
)
)
)
5 REPLIES 5
Greg_Deckler
Community Champion
Community Champion

I would say that is likely, you generally do not re-calculate a VAR. I'm actually sort of surprised it lets you do it and you don't get a syntax error. Tough to say really without sample data. Is the 2nd one giving you the correct result that you are looking for?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Yes the second one is doing the job. But there i do not use the variable.

Is the second one using a measure? Just curious. 

 

But, yes, once you set a VAR it doesn't change in value, unless you get into nesting like in my Runge-Kutta Quick Measure but that's a very specialized case. 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

The second one also uses measures. See next

This calculates the amount to pay to to the workforces for the previous Fiscal year. Because these Fiscal years are not always from jan untill dec and change per yaer. Also it is not the same for every company in my dataset. So actualy it is the same as calculate([_personeel];previousyear(_Boekperiod[Date])) but because i need to look at so many different factors i need to calculate it like this one underneath. This measure does work.

 

Personeel PFY =

IF (
HASONEVALUE ( _Boekperiod[tdboekper_boekper] );
IF (
HASONEVALUE ( _Boekperiod[Bedrijf] );
//For Single Company
CALCULATE (
[_Personeel];
FILTER (
ALL ( _Boekperiod );
_Boekperiod[Boekjaar]
= SELECTEDVALUE ( _Boekperiod[Boekjaar] ) - 1
&& _Boekperiod[tdboekper_boekper]
= SELECTEDVALUE ( _Boekperiod[tdboekper_boekper] )
&& _Boekperiod[Bedrijf] = SELECTEDVALUE ( _Boekperiod[Bedrijf] )
)
);
//For All Companies (total)
CALCULATE (
[_Personeel];
FILTER (
ALL ( _Boekperiod );
_Boekperiod[Boekjaar]
= SELECTEDVALUE ( _Boekperiod[Boekjaar] ) - 1
&& _Boekperiod[tdboekper_boekper]
= SELECTEDVALUE ( _Boekperiod[tdboekper_boekper] )
)
)
);
IF (
HASONEVALUE ( _Boekperiod[Bedrijf] );
//For Single Company
CALCULATE (
[_Personeel];
FILTER (
ALL ( _Boekperiod );
_Boekperiod[Boekjaar]
= SELECTEDVALUE ( _Boekperiod[Boekjaar] ) - 1
&& _Boekperiod[Bedrijf] = SELECTEDVALUE ( _Boekperiod[Bedrijf] )
)
);
//For All Companies (total)
CALCULATE (
[_Personeel];
FILTER (
ALL ( _Boekperiod );
_Boekperiod[Boekjaar]
= SELECTEDVALUE ( _Boekperiod[Boekjaar] ) - 1
)
)
)
)

 

 

 

Hi @jvangrunderbeec

 

Yes, once you declare a variable its contents are immutable, a constant actually.

In [Bedrag PFY] you're using the variable Calculateddmeasure  in the first argument of the CALCULATE. Its contents will not change, it is not affected by the filter arguments. It's like if you did  CALCULATE( 3, FILTER( .....)), you'd always get a 3

 

In [Bedrag PFY2], on the contrary, you are using the measure [Bedrag (c)] directly instead of the variable and that gets recalculated within the filter context created by CALCULATE, as usual.

  

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! It's time to submit your entry.

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.