Reply
avatar user
Anonymous
Not applicable

How DAX Execute VAR/ RETURN

Hi!

I'm just curious how does DAX execute VAR/ RETURN lines? Will it

  1. execute/ evaluate all the VARs first then RETURN values based on the VARs? or 
  2. will it run RETURN first then check which VARs are necessary then evaluate only those VARs?

For example I have a measure with the following lines below. Since I did not use VAR2 in my RETURN statement, will it still evaluate VAR2?

 

Measure = 
VAR1 = SUM(Table[Column1])
VAR2 = SUM(Table[Column2])
VAR3 = SUM(Table[Column3])

RETURN
DIVIDE(VAR1, VAR3)

Thanks!

 

1 ACCEPTED SOLUTION
AlB
Community Champion
Community Champion

Hi @Anonymous 

The compiler will check for potential errors but at execution time the variable will only be evaluated if it's invoked in the RETURN part. For instance:

Measure = 
VAR VAR1 = SUM(Table1[Column1])
VAR VAR2 = 3/VALUES(Table1[Column1])
VAR VAR3 = SUM(Table1[Column1])
RETURN
VAR1

will NOT generate an error even though at VAR2 we are dividing by a column but this will:

 

Measure = 
VAR VAR1 = SUM(Table1[Column1])
VAR VAR2 = 3/VALUES(Table1[Column1])
VAR VAR3 = SUM(Table1[Column1])
RETURN
VAR2

 

View solution in original post

1 REPLY 1
AlB
Community Champion
Community Champion

Hi @Anonymous 

The compiler will check for potential errors but at execution time the variable will only be evaluated if it's invoked in the RETURN part. For instance:

Measure = 
VAR VAR1 = SUM(Table1[Column1])
VAR VAR2 = 3/VALUES(Table1[Column1])
VAR VAR3 = SUM(Table1[Column1])
RETURN
VAR1

will NOT generate an error even though at VAR2 we are dividing by a column but this will:

 

Measure = 
VAR VAR1 = SUM(Table1[Column1])
VAR VAR2 = 3/VALUES(Table1[Column1])
VAR VAR3 = SUM(Table1[Column1])
RETURN
VAR2

 

avatar user

Helpful resources

Announcements
March PBI video - carousel

Power BI Monthly Update - March 2025

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

March2025 Carousel

Fabric Community Update - March 2025

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

Top Solution Authors (Last Month)
Top Kudoed Authors (Last Month)