Format
SingleValueIf(Condition ,ValueIfTrue ,ValueIfFalse)
Returns
Returns the value of the ValueIfTrue expression if the Condition expression evaluates to true. Otherwise, returns the value of the ValueIfFalse expression.
Inputs
Condition: The expression to be evaluated.
Behaviour: Required
Dimension: Collection, SingleValue
Valid data types: Boolean
ValueIfTrue: The value returned if the condition evaluates to true.
Behaviour: Required
Dimension: Error, Collection, SingleValue, Matrix, MultiCollection
Valid data types: Null, Boolean, DateTime, Decimal, Integer, String, Duration, Error
ValueIfFalse: The value returned if the condition evaluates to false.
Behaviour: Required
Dimension: Error, Collection, SingleValue, Matrix, MultiCollection
Valid data types: Null, Boolean, DateTime, Decimal, Integer, String, Duration, Error
Common Traps
If a collection is used for the condition, it must contain only 1 value. If the condition is a collection which contains 0 or more than 1 value, the function will return an error.
When to Use
The SingleValueIf() function takes a single value and returns a value which is either the true or false parameter, whereas If() takes the individual values in the collections and compares them, returning a collection comprised of the individual evaluations.
Here are some examples which show the difference:
If([1, 1, 2, 2] >= 2, [5, 5, 5, 5], [2, 2, 2, 2]) = [2, 2, 5, 5]
SingleValueIf([1] >= 2, [5, 5, 5, 5], [2, 2, 2, 2]) = [2, 2, 2, 2]
SingleValueIf([2] >= 2, [5, 5, 5, 5], [2, 2, 2, 2]) = [5, 5, 5, 5]
Examples
Expression: SingleValueIf({tagname}>=2,[5, 5, 5, 5], [2, 2, 2, 2])
Result: If the value of {tagname} is greater than or equal to 2, return [5, 5, 5, 5]. Otherwise, return [2, 2, 2, 2].
Example outcomes:
Where tagname is [1], the function returns [2, 2, 2, 2].
Where tagname is [], the function returns an error, because the collection contains 0 values.
Where tagname is [1,2,3], the function returns an error, because the collection contains more than 1 value.
Expression: SingleValueIf({tagname}>=0,{tagname},"Too Low")
Result: If the value of {tagname} is greater than or equal to zero, return the value of the tag. Otherwise, return the string "Too Low".
Release History
- SingleValueIf() 4.6.5
- Changed ValueIfTrue and ValueIfFalse parameters to support MultiCollection values.
- SingleValueIf() 4.0
- Initial version