SheetRocks
Documentation/Formulas/SWITCH

SWITCH

Evaluates an expression against a list of values and returns the result corresponding to the first matching value. Optionally returns a default value if no match is found.

Syntax

SWITCH(expression, value1, result1, [value_n], [result_n], [default])

Arguments

Argument Description Required
expression Value to match against. Required
value1 First value to compare with expression. Required
result1 Result to return if value1 matches. Required
value_n Additional value to compare with expression. Optional
result_n Additional result to return if value_n matches. Optional
default [OPTIONAL] Value to return if no matches found. If even number of arguments, last argument is treated as default. Optional

Examples

Match with string values

=SWITCH("B", "A", "First", "B", "Second", "C", "Third")
Result ⇒ Second

Match with numbers and default value

=SWITCH(2, 1, "One", 2, "Two", 3, "Three", "Other")
Result ⇒ Two

No match with default value

=SWITCH("X", "A", 1, "B", 2, "Unknown")
Result ⇒ Unknown

Match grade letter

=SWITCH(A1, "A", "Excellent", "B", "Good", "C", "Average", "Needs improvement")
Result ⇒ Excellent
A
1 A

Related Functions

Other Logical functions:


← Back to Formula Reference