Going Stellar

Home/Google Sheets reference

Google Sheets function · Logical

SWITCH in Google Sheets: syntax and examples

SWITCH checks one expression against a list of cases and returns the value paired with the first case that is equal. A final unpaired value acts as the default. It reads better than nested IF when you map codes to labels.

Syntax

SWITCH(expression, case1, value1, [default or case2, value2], …)

Arguments

ArgumentTypeRequiredWhat it does
expressionanyyesThe value that is compared with each case, in order.
case1anyyesThe first value to compare with expression.
value1anyyesWhat is returned when expression equals case1.
default or case2, value2, …anynoMore case and value pairs. A last value without a pair is the default result.

Examples

The examples use this table, starting in A1:

CodeSizeScoreDay
1S951
2M726
3L407
4XL583
=SWITCH(A2, 1, "Low", 2, "Medium", 3, "High")

Result: Low

Turns a code into a label. The first case that equals A2 wins.

Run in a Google Sheet (English US locale) on .

=SWITCH(A5, 1, "Low", 2, "Medium", 3, "High", "Other")

Result: Other

Code 4 has no case, so the last lone value, "Other", is returned as the default.

Run in a Google Sheet (English US locale) on .

=SWITCH(B3, "s", "Small", "m", "Medium", "l", "Large")

Result: Medium

Text cases ignore case: the cell holds M and the case is m.

Run in a Google Sheet (English US locale) on .

=SWITCH(TRUE, C3>=90, "A", C3>=70, "B", "C")

Result: B

With TRUE as the expression, each case can be a test. The first true test returns its value.

Run in a Google Sheet (English US locale) on .

=SWITCH(D3, 6, "Weekend", 7, "Weekend", "Weekday")

Result: Weekend

Several cases can return the same value. Day 6 is mapped to Weekend.

Run in a Google Sheet (English US locale) on .

Common errors

  • Without a default, a value that matches no case returns #N/A. Add a last lone value, or wrap the formula in IFERROR.
  • The match is by equality only, and the types must agree. The text "1" does not equal the number 1, so the result is #N/A.
  • A case without its value, such as SWITCH(A2, 1), returns #N/A. Every case needs a value right after it.
  • For ranges such as scores, SWITCH needs TRUE as the expression. With a number as the expression, a test like C2>=90 is compared with the number and never matches. IFS is shorter for that job.

Compared with Excel

Same syntax as Excel SWITCH. Excel added it in 2019, so older versions lack it.

Questions and answers

When should I use IFS instead of SWITCH?

Use SWITCH when one value is compared for equality with many options. Use IFS when every branch needs its own test, such as ranges of scores.

Sources

  1. SWITCH (Docs Editors Help)

Markdown version · All functions