SWITCH

Compares the input expression against a list of values and returns the corresponding result for the listed value upon first match. If no match is found, the default values is returned.

Syntax 

SWITCH(expression, value_to_compare, value_to_return, ..., default_value)

Usage examples 

Example 1

Formula

SWITCH(1+1, 2, 'true!', 1, 'false!', 'error!')

Output

"true!"

Example 2

Input

1
{
2
"day_of_week": "sunday"
3
}

Formula

SWITCH(day_of_week, 'monday', 'working', 'saturday', 'weekend', 'error')

Output

"error"

Example 3

Input

1
{
2
"status": "approved"
3
}

Formula

SWITCH(status, 'pending', 'yellow', 'approved', 'green', 'rejected', 'red', 'gray')

Output

"green"

Example 4

Input

1
{
2
"score": "F"
3
}

Formula

SWITCH(score, 'A', 'Excellent', 'B', 'Good', 'C', 'Average', 'Needs Improvement')

Output

"Needs Improvement"
Was this helpful?