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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
daxreport
Frequent Visitor

VAR Statement and Time Intelligence

Hello, 

 

I have an issue with using time intelligence function and VARIABLES. 

 

Below code works fine: 

 

PY Volume = 
CALCULATE ( [BlendedQty], SAMEPERIODLASTYEAR ( DIM_CALENDAR[Date] ) )

 

However, below code which basically is the same thing but using VAR statements.  What am I doing wrong? Thanks 

 

PY VolumeTEST = 
VAR Qty = [BlendedQty]
VAR PreviousQTY = CALCULATE(Qty,SAMEPERIODLASTYEAR(DIM_CALENDAR[Date]))
RETURN
    PreviousQTY

 

1 ACCEPTED SOLUTION
eliasayyy
Memorable Member
Memorable Member

Hello @daxreport 

When calculated as a variable first it is in the evaluation context of the visual.  Putting the variable inside the CALCULATE(variable, SAMEPERIODLASTYEAR(...  does not recalculate the expression in the desired new evaluation context.

View solution in original post

2 REPLIES 2
some_bih
Super User
Super User

Hi @daxreport variables in DAX are simply lazy evaluation processed, meaning once calculated it is fixed value / amount. So when you want to reuse it in CALCULATE for context transition, this is what CALCULATE DO, then results could be unexpected (your second measure with VAR).

Did I answer your question? Mark my post as a solution! Kudos Appreciated!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!






eliasayyy
Memorable Member
Memorable Member

Hello @daxreport 

When calculated as a variable first it is in the evaluation context of the visual.  Putting the variable inside the CALCULATE(variable, SAMEPERIODLASTYEAR(...  does not recalculate the expression in the desired new evaluation context.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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