The SWITCH function compares an expression to multiple cases and returns the first matching value, as text. It is useful when several conditions need to be tested in a single formula, and can replace sequences of nested IF()s.
The output format of the result can be configured in the output field options of the formula editor. For more details, see Output format options in the Formula column article.
Syntax
SWITCH(
source,
value_1, result_1,
value_2, result_2,
... ,
default_value
)
Calling function parameters in TimeTonic:
- $field_name = field (link, linked table column, number, selection, formula, text...).
- "free text" = free text to add between quotation marks.
- Do not use quotation marks for numbers.
Parameters
Examples
Map a status to a display value
Suppose a column Status containing: "New", "In Progress", "Completed".
SWITCH(
Status,
"New", "🔴 Urgent",
"In Progress", "🟡 In progress",
"Completed", "✅ Closed",
"Cancelled", "⚫ Cancelled",
"Unknown"
)
Result: "New" if the status is 🔴 Urgent. Each status value is mapped to a result, and a default value is provided for uncovered cases.
Why use SWITCH instead of IF? SWITCH() replaces sequences of nested IF()s with logic that is more readable, easier to maintain, and less error-prone. It is recommended as soon as you need to handle more than 3 conditional cases.
Go further
IF
The simple IF... THEN... ELSE condition, for a single case.
Or continue with
Formula glossary
All available operators and functions, sorted by category.