1. Home
  2. Functions
  3. Logical
  4. SWITCH

SWITCH function

Compares a value with a list of cases and returns the result of the first match, or a default.

Syntax

=SWITCH(expression, value1, result1, [default], ...)

Arguments

ArgumentRequiredDescription
expressionRequiredThe value to compare
value1RequiredA case to compare with
result1RequiredThe result for that case
defaultOptionalThe result when nothing matches (optional, last argument)

How to use SWITCH

SWITCH takes 3 required arguments and 1 optional argument, and accepts more values in the same pattern. Type =SWITCH( in a cell and SheetsBat shows the arguments as you go. Optional arguments are shown in square brackets; leave them out to use their default.

Examples

Each result below was calculated by the SheetsBat formula engine.

=SWITCH(2, 1, "one", 2, "two", "other")Result "two"
=SWITCH(9, 1, "one", "other")Result "other"
=SWITCH(9, 1, "one")Result #N/A

Every formula, right in your browser

SheetsBat calculates 536 functions, with charts, pivot tables and live collaboration. Free to start.