SWITCH function in Excel
Evaluates an expression against a list of values and returns the result corresponding to the first matching value. If there is no match, an optional default value may be returned.
=SWITCH(expression, value1…value126, result1…result126, [default])SWITCH syntax and parameters
Four arguments, three required.
- expressionanyRequired
Expression is the value (such as a number, date or some text) that will be compared against value1…value126.
- value1…value126anyRepeating
ValueN is a value that will be compared against expression.
- result1…result126anyRepeating
ResultN is the value to be returned when the corresponding valueN argument matches expression. ResultN and must be supplied for each corresponding valueN argument.
- defaultanyOptional
Default is the value to return in case no matches are found in the valueN expressions. The Default argument is identified by having no corresponding resultN expression (see examples). Default must be the final argument in the function.
SWITCH examples
Formulas you'll actually reuse.
Commission rate by region, with a default for everything else:
=SWITCH(A2, "West", 0.08, "North", 0.07, "South", 0.06, 0.05)Result
0.08Weekend or weekday from a date — several cases, one fallback:
=SWITCH(WEEKDAY(E2, 2), 6, "Weekend", 7, "Weekend", "Weekday")Result
"Weekday"
SWITCH in Google Sheets
Same name — your formula ports as-is.
Try SWITCH in the playground
Edit the example — nothing to install.
Preloaded with the SWITCH formula from Example 1 — change anything and watch it respond.
SWITCH errors
What they mean — and the fixes.
#N/ANo case matched and no default was given — add a final unpaired argument as the fallback.
Related functions
More ways Excel gets this done.
- ANDReturns TRUE if all of its arguments are TRUELogicalGoogle Sheets
- BYCOLApplies a LAMBDA to each column and returns an array of the resultsLogicalGoogle Sheets
- BYROWApplies a LAMBDA to each row and returns an array of the resultsLogicalGoogle Sheets
- FALSEReturns the logical value FALSELogicalGoogle Sheets
- IFSpecifies a logical test to performLogicalGoogle Sheets
- IFERRORReturns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formulaLogicalGoogle Sheets