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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Anonymous
Not applicable

Why do Var and Measure give different results?

I want to calculate the conditional max date in a table and reuse that date for differnt tasks i.e calculate week offsets.  

 

CurrWeekOffset is mostly blank if I use the Measure to calculate the column.

// Measure 
Max_Ist_Date = 
  CALCULATE (
    MAX (Table[Date] ),
    FILTER( Table, Table[Source.Table] = "Something" )
   )

 

// Calculated Column in Table2

Max_Ist_Date = 
  CALCULATE (
    MAX (Table[Date] ),
    FILTER( Table, Table[Source.Table] = "Something" )
   )
CurrWeekOffset =   
                DATEDIFF ([Max_Ist_Date],[Date],WEEK)

 

However, it works if I use the same code as a VAR.

 

VAR Max_Ist_Date = 
  CALCULATE (
    MAX (Table[Date] ),
    FILTER( Table, Table[Source.Table] = "Something" )
   )
RETURN     
     DATEDIFF (Max_Ist_Date,[Date],WEEK)

 

What is going on here? 
 

1 ACCEPTED SOLUTION
AilleryO
Memorable Member
Memorable Member

Hi,

 

In fact quite a lot of things happening around 😉

When you use a variable in Power BI the calculation is made before the rest of the calculation and the value is stored. So what you are facing is question of evaluation context and when is calculated what.

The content (rows and columns) of the table in which you're displaying your measure has an impact on the calculation.

More information on using variable in this article or  from SQLBI.

You should try as well to work with MAXX when using measure and when iteration is needed, otherwise Power BI might consider an agregated value.

It has no impact when you are creating a calculated column because calculated columns are using the row context of the table they have been created in. So a calculated column always iterates whereas a measure can iterate, if you ask for it (for instance using  ...X functions like SUMX or MAXX or MINX...).

 

Hope it gives you some tracks to understand more what going on...

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Thank you for the references. I'll give MAXX a try. 

AilleryO
Memorable Member
Memorable Member

Hi,

 

In fact quite a lot of things happening around 😉

When you use a variable in Power BI the calculation is made before the rest of the calculation and the value is stored. So what you are facing is question of evaluation context and when is calculated what.

The content (rows and columns) of the table in which you're displaying your measure has an impact on the calculation.

More information on using variable in this article or  from SQLBI.

You should try as well to work with MAXX when using measure and when iteration is needed, otherwise Power BI might consider an agregated value.

It has no impact when you are creating a calculated column because calculated columns are using the row context of the table they have been created in. So a calculated column always iterates whereas a measure can iterate, if you ask for it (for instance using  ...X functions like SUMX or MAXX or MINX...).

 

Hope it gives you some tracks to understand more what going on...

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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.