Syntax
=SWITCH(expression, value1, result1, [default], ...)Arguments
| Argument | Required | Description |
|---|---|---|
expression | Required | The value to compare |
value1 | Required | A case to compare with |
result1 | Required | The result for that case |
default | Optional | The 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 =SWITCH(9, 1, "one", "other")Result =SWITCH(9, 1, "one")Result Related logical functions
- IFERRORReturns a value of your choice when a formula gives an error, otherwise the formula result.
- IFNAReturns a value of your choice when a formula gives #N/A, otherwise the formula result.
- IFSChecks conditions in order and returns the value of the first one that is TRUE.
- LAMBDACreates a reusable function with parameters. Call it right away, store it in a name or pass it to MAP, REDUCE and friends.
- LETNames the results of calculations so a formula can reuse them.
- NOTReverses a logical value.
- ORTRUE when any argument is TRUE.
- TRUEThe logical value TRUE.
- XORTRUE when an odd number of arguments are TRUE.