The SWITCH() function allows you to compare an expression to multiple cases and return the first matching value. It is useful when several conditions need to be tested in a single formula and can replace sequences of nested IF()s.
Logical function name:
SWITCH()
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 be added between quotation marks.
- do not use quotation marks for numbers.
Parameters
| Parameter | Description |
|---|---|
source |
A single value to compare to the defined values. |
value_1, value_2, ... |
Defined value to compare source to. |
result_1, result_2, ... |
Value returned if source matches value_1, value_2, ...,
|
default_value |
Value returned if no value matches. |
Example
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 associated with a result and a default value is provided for uncovered cases.
Notes
The function evaluates the expression and returns the first match. If there is no match, the default value is returned.
This function can replace sequences of nested
IF()s.
Return type
The SWITCH() function returns text.
The output type 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.
“Why use SWITCH instead of IF?”
SWITCH() allows you to replace 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 manage more than 3 conditional cases.