Forum Discussion
Anonymous
7 years agoNot applicable
How DAX Execute VAR/ RETURN
Hi! I'm just curious how does DAX execute VAR/ RETURN lines? Will it execute/ evaluate all the VARs first then RETURN values based on the VARs? or will it run RETURN first then check which VARs...
- 7 years ago
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
AlB
Community Champion
7 years agoHi 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