SWITCH(expression, case1, value1, [default or case2, value2], …)One free generation or explanation per browser, shared across Excel and Google Sheets. Account usage limits apply afterward.
expression:
The value or expression that you want to evaluate against the specified cases.
case1:
The first case to compare against the expression. If the expression matches this case, the corresponding value1 will be returned.
value1:
The value that will be returned if the expression matches case1.
default or case2:
An optional additional case to compare against the expression. If the expression matches this case, the corresponding value2 will be returned. You can include multiple cases and values in this format.
value2:
The value that will be returned if the expression matches case2. This can be repeated for additional cases and values.
The SWITCH function in Google Sheets is a useful tool that allows you to evaluate a single expression against a list of values and return a corresponding result. It simplifies the process of handling multiple conditions by eliminating the need for nested IF statements. This function is particularly handy when you have a fixed set of possible outcomes.
In simpler terms, SWITCH lets you check a value against several cases and return a specific result based on which case matches.
Imagine you are managing a grading system for students based on their scores:
| StudentID | Score |
|---|---|
| 1 | 85 |
| 2 | 72 |
| 3 | 90 |
| 4 | 60 |
You want to assign a letter grade based on the score, where:
To achieve this, you would use the SWITCH function as follows:
=SWITCH(TRUE,
B2 >= 90, "A",
B2 >= 80, "B",
B2 >= 70, "C",
B2 >= 60, "D",
"F")In this formula:
TRUE is the expression being evaluated.B2 against the specified thresholds.When you apply the SWITCH formula to the Scores Table, the output would look like this:
| StudentID | Score | Grade |
|---|---|---|
| 1 | 85 | B |
| 2 | 72 | C |
| 3 | 90 | A |
| 4 | 60 | D |
SWITCH is beneficial because it streamlines the process of evaluating multiple conditions in your spreadsheet. It makes your formulas easier to read and maintain compared to using nested IF statements. Additionally, it reduces the likelihood of errors in complex logical evaluations.
SWITCH is an essential function for anyone working with data in Google Sheets, providing a powerful way to simplify logical evaluations and enhance data organization.
Happy spreadsheeting!
You have a table where Column A lists product codes and Column B contains their categories. You can use the SWITCH formula to categorize a specific product code, allowing for quick identification of its category without nested IF statements.
Sign up for Better Analyst and get unlimited AI-powered formula generation, explanations, and advanced data analysis.
Browse our complete library of Google Sheets formula guides
Compare your options
Open a neutral research prompt in the AI tool you already use. Compare capabilities, limitations, and fit before you choose.
AI answers can be incomplete. Check source links, current pricing, and product documentation before deciding.