Forum Discussion
DAX interpreter BUG!!!
PBI Desktop vs = July 2022
- v-easonf-msft4 years ago
Community Support
Hi, Element115
Although variables can be used anywhere, however, their result might not be always the same. Because they are evaluated in the context in which they are written.
Please refer to this thread for more details.
Caution When Using Variables in DAX and Power BI
Best Regards,
Community Support Team _ Eason- Element1154 years ago
Memorable Member
TBH what you are saying makes no sense to me: variables
are evaluated in the context in which they are written.Variables should be visible in the scope in which they are declared, period. Are you saying that DAX scoping isn't following what we are used to with all major programming languages out there?
In any case, all my variables are usually declared top level, ie right after the 'MeasureName = ' line. Therefore I would expect this scope to be visible all the way down to the RETURN statement.
Isn't it so?
- Element1154 years ago
Memorable Member
One more thing... I read RADACAD's explanation, however it does not apply here. Look again carefully at the code I posted:
"DownTime", IF ( [ErrorCategory] == "Unreachable", VAR __unreachable_dt = DATEVALUE([UnreachableSince]) + TIMEVALUE([UnreachableSince]) VAR __unreachable_dt_in_secs = DATEDIFF(__start_date, __unreachable_dt, SECOND) RETURN IF( __unreachable_dt_in_secs >= 0, DATEDIFF(DATEVALUE([UnreachableSince]) + TIMEVALUE([UnreachableSince]), [ClosedDT], SECOND), BLANK() //DATEDIFF([CreationDT], [ClosedDT], SECOND) ),__unreachable_dt is declared right before the RETURN statement and when referenced in the RETURN block inside de DATEDIFF() inside the IF() as the 2nd parameter, the result is not that the computation is wrong.
In other words, the block of code isIF( condition, VAR __declaration0 = ... VAR __declaration1 = ... RETURN IF( __declaration1 >= 0, // no issues here referencing the second variable DATEDIFF( __declaration0, ... ) // issue here CAN'T FIND THE VARIABLE!!! ... Is this really as it should be???The result is that the interpreter complains the variable does not exist or is not defined! Two very different things, yes?
- Element1154 years ago
Memorable Member
Hello, any updates?