How to implement conditional exit to PI AF Analysis

Below, you'll see that the analysis variable "Variable1" has the following expression:

 

If HasValueChanged(LastEval) then

1

else

2

 

When previewing results, Variable1 usually evaluates to 2, but sometimes evaluates to 1.

 

When I replace "2" in the else condition with an Exit() call, Variable1 no longer evaluates to 1 when it is supposed to, but now calls the Exit function instead, even when the if-statement condition still evaluates to true, which is not the desired functionality.

 


Last previewed result evaluates to 1..png
 


Last previewed result evaluates to Exit() even though it previousl.png