How to Use the SWITCH Function in Excel

Today, we’ll delve into the SWITCH function in Excel and Google Sheets. This function compares an expression against a set of values and returns a result for the first match found. It is particularly useful for streamlining complex nested IF statements, as it allows you to handle multiple conditions and outcomes within a single formula.

Basic Syntax

The syntax for the SWITCH function is consistent across both Excel and Google Sheets:

=SWITCH(expression, value1, result1, [default_value or value2, result2], ... [default_value, default_result])
  • expression: The value or expression you want to evaluate.
  • value1: The first value to which the expression is compared.
  • result1: The outcome returned if there is a match between the expression and value1.
  • value2, result2: Additional pairs of values and their corresponding outcomes to consider.
  • default_value: An optional value used if no other specified values match the expression.
  • default_result: The outcome returned if there are no matches to any given value (associated with the default_value).

Examples

Let’s explore some practical examples to better understand the SWITCH function:

Example Description Excel Formula Result
Example 1 Check the day of the week. =SWITCH(A2, 1, "Sunday", 2, "Monday", 3, "Tuesday", 4, "Wednesday", 5, "Thursday", 6, "Friday", 7, "Saturday", "Unknown") If A2 = 1, returns “Sunday”; if A2 = 2, returns “Monday”, and so on up to 7. Returns “Unknown” if A2 is outside 1-7.
Example 2 Assign grades based on scores. =SWITCH(B2, 1, "Fail", 2, "Pass", 3, "Merit", 4, "Distinction", "Invalid Score") If B2 = 1, returns “Fail”; if B2 = 2, returns “Pass”; and so forth. Returns “Invalid Score” if B2 does not match 1, 2, 3, or 4.

Conclusion

The SWITCH function is an invaluable tool for managing conditional logic in Excel and Google Sheets. It offers a more succinct and clear approach to handling multiple conditions in your formulas. By mastering the syntax and examples provided, you can leverage the SWITCH function to enhance the efficiency and clarity of your spreadsheet tasks.

More information: https://support.microsoft.com/en-us/office/switch-function-47ab33c0-28ce-4530-8a45-d532ec4aa25e

Other functions
Vrátí hodnotu PRAVDA, pokud mají všechny argumenty hodnotu PRAVDA
Returns TRUE if all of its arguments are TRUE
Returns the logical value FALSE
Určí, který logický test má proběhnout
Vrátí hodnotu PRAVDA, je-li alespoň jeden argument roven hodnotě PRAVDA
Specifies a logical test to perform
Returns a value you specify if a formula evaluates to an error; otherwise, returns the result of the formula
Pokud je vzorec vyhodnocen jako chyba, vrátí zadanou hodnotu V opačném případě vrátí výsledek vzorce
Returns the value you specify if the expression resolves to #N/A, otherwise returns the result of the expression
Pokud je výsledkem vzorce chybová hodnota #NENÍ_K_DISPOZICI, vrátí tato funkce hodnotu, která jí byla zadána V opačném případě vrátí výsledek vzorce
Checks whether one or more conditions are met and returns a value that corresponds to the first TRUE condition
Zkontroluje splnění jedné nebo více podmínek a vrátí hodnotu odpovídající první podmínce, která nabývá hodnoty PRAVDA
Provede logickou negaci argumentu funkce
Vrátí logickou hodnotu NEPRAVDA
Reverses the logic of its argument
Returns TRUE if any argument is TRUE
Vrátí logickou hodnotu PRAVDA
Porovná hodnotu výrazu se seznamem hodnot a jako výsledek vrátí první shodnou hodnotu Pokud nenajde žádnou shodu, může vrátit volitelnou výchozí hodnotu
Returns the logical value TRUE
Returns a logical exclusive OR of all arguments
Vrátí hodnotu logické operace XOR pro všechny argumenty