This is an old revision of the document!
Table of Contents
If(condition, when_true, when_false)
Category: Logical function
Description
This action creates binary decision logic by evaluating the supplied condition and returning the when_true value if the condition is true, or when_false if not.
Arguments
Argument | Type | Description |
---|---|---|
condition | Expression | This is an expression or "test" that evaluates to either TRUE or FALSE. |
when_true | Expression | If the condition evaluates to TRUE, this value is returned. |
when_false | Expression | If the condition evaluates to FALSE, this value is returned. |
Return value type: Text, Number, Boolean (the value types used for when_true and when_false)
Remarks
To return a Boolean TRUE or FALSE value, use the True() and False() functions.
If() functions can be nested to provide decisions based on more than a single test, and return a value from more than just two choices. See examples below.
Examples
if(2+2=4, "Yes it does", "No it doesn't") = "Yes it does" //Returns the text value. if("This" = "That", 1, 0) = 0 //Returns numeric zero. if(rem(4,2)=0,"Number is even","Number is odd") = "Number is even" //Using a function in the condition. if({MyVal}+6=8,"MyVal is 2","MyVal is not 2") = "MyVal is not 2" //Where "MyVal" = 3, parameters are supported.
Nested if()s
Another "level" of logic can be introduced by using a nested if() for the outer if()'s TRUE and/or FALSE value(s). This becomes the equivalent of an "elseif" branch.
if( [Field1)>10, "More than 10", if( [Field1]>0, "More than 0, less than 10", "Less than 0" ) )
If [Field1] is greater than 10, the condition is evaluated to TRUE and the when_true value ("More than 10") is returned. However, if the condition is evaluated to FALSE, the when_false "value" is another if() test, which is evaluated. In this case, if [Field1] is greater than 0, "More than 0" is returned, otherwise "Less than 0" is.
Nested if()s can be used for the condition, the when_true, and/or the when_false values.