IFS
returns the value that corresponds to the first logical expression that evaluates to TRUE.
Function category: Logical​
IFS
expects an even number of arguments.
IFS(cond1, expr1, ... , condN, exprN)
Arguments | Description |
| Condition that evaluates to a truthy or a falsy value. |
| Expression that is evaluated only when corresponding condition returns a truthy value. Result is returned as a result of |
| Nth condition. |
| Nth expression. |
In the following context we use MAP
to walk through a list of users fetched from the context. Then we apply IFS
to fetch the surname attribute from each of them. In the cases where a surname is not defined, we return a placeholder text.
{"users": [{"name": "Jones","surname": "George"},{"name": "Smith"}]}
We will use the following function.
# Find first value that returns trueMAP(IFS(_.surname <> NULL, _.surname, _.surname = NULL, 'Unknown surname'), users)​# Returns ["George", "Unknown surname"]
See also: MAP function.