Google Sheets SWITCH function

Compares a value with a list of cases and returns the matching one’s result. In Spanish Sheets it is called CAMBIAR.

Syntax

English Sheets

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

Spanish Sheets (Mexico locale)

=CAMBIAR(expresión, caso1, valor1, [predeterminado o caso2, valor2], …)

Spanish Sheets (Spain, Latin America)

=CAMBIAR(expresión; caso1; valor1; [predeterminado o caso2; valor2]; …)

ArgumentWhat it is
expressionThe value to compare.
case1The first option.
value1What it returns on a match.
default or case2, value2optionalMore pairs, or a last unpaired value as the default.

Example

SWITCH(expression, case1, value1, case2, value2…, default) compares a value with a list of cases. It is ideal for turning codes into names.

=SWITCH(B2,"N","North","S","South","Central")

Common mistake

Without a default, an unknown code returns #N/A.

About Ads

This site uses Google AdSense to display ads. These ads help us keep WebHerramientas completely free. Ads are managed by Google and meet strict security and privacy standards.

Advertising
Loading ad...

Ads help us keep WebHerramientas free for everyone

Practice SWITCH

Type the formula in the sheet and check it instantly. Spanish or English function names both work. See all lessons

SWITCH

SWITCH(expression, case1, value1, case2, value2…, default) compares a value with a list of cases. It is ideal for turning codes into names.

Example=SWITCH(B2,"N","Norte","S","Sur","Centro")CAMBIAR = SWITCH

In C2, translate the code: N is "North", S is "South" and anything else is "Central".

C2
ABCD
1OrderCodeRegion
2P-01N
3P-02S
4P-03C
5P-04N
6P-05S
7

Tip: while typing, click a cell or drag across several to insert their reference.

Frequently asked questions

What is SWITCH called in Spanish?
In Spanish Google Sheets it is CAMBIAR. The formula =SWITCH(B2,"N","North","S","South","Central") is written =CAMBIAR(B2;"N";"Norte";"S";"Sur";"Centro") (or with commas under a Mexico locale).
Why does SWITCH use semicolons in some spreadsheets?
It depends on each spreadsheet's locale, under File > Settings. Where the comma is the decimal mark (Spain, much of South America), arguments are separated by semicolons. Mexico and United States locales use commas.
What is the most common SWITCH mistake?
Without a default, an unknown code returns #N/A.