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