SWITCH Function

What is the SWITCH Function?

The SWITCH function is categorized under Excel’s Logical functionsFunctionsList of the most important Excel functions for financial analysts. This cheat sheet covers 100s of functions that are critical to know as an Excel analyst. This function will evaluate a given expression (or a value) against a list of values and will return a result corresponding to the first matching value. In case there is no matching value, an optional default value will be returned.

SWITCH was added in MS Excel 2016 and is unavailable in earlier versions. However, the function was previously available in VBA. The SWITCH function can be used instead of nested IF functions.

Formula

Expression (required argument) – It can be a number, date, or some text that the function would compare. A few examples of the expression argument are as follows:

Type of Expression

Example

Cell reference

A2

Logical test

A2=“PASS”

Number or text

2 or “FAIL”

Named range

Named_Range

Boolean values

TRUE or FALSE

Math expression

A2+1

Value1 ………value126 (required argument) – This is the value that will be compared against the expression.

Result1 ………result126 – The value that will be returned when the corresponding valueN argument matches the expression.

Default (optional argument) – This is the value that the function should return if no matches are found in the valueN expression.

How to use the SWITCH Function in Excel?

Let’s see a few examples to understand how the SWITCH function works:

Example 1

Let’s assume we are given a series of acronyms and we wish to return the value that the acronyms stand for.

The formula will be =SWITCH(A6,”DR”,”Debtors”,”CR”,”Creditors”,”JE”,”Journal Entry”,”LB”,”Ledger book”,”unknown”).

We get the result below:

If we need to use an IF nested formula, it would be a long formula. Both SWITCH function and IF function help us to specify a series of conditions. However, with SWITCH, we can define an expression and a sequence of values and results, not several conditional statements.

The best part of the SWITCH function is that we don’t need to repeat the expression several times, which sometimes happens in nested IF formulas.

Example 2 – Using SWITCH with other functions

Suppose we are given a few dates and we want to see if they refer to present day, tomorrow, or yesterday. Using the SWITCH, DAYS, and TODAY functions together, we can achieve the desired results.

The TODAY function will return the serial number of the current date, and the DAYS function will return the number of days between two dates.

The formula to use is =SWITCH(DAYS(TODAY(),B5), 0, “Present date”, 1,”Yesterday”, -1,”Tomorrow”,”Unknown”).

Example 3

In some countries, the financial year starts on a date other than January 1, so they often need to classify dates into fiscal quarters. For example, if April to March is the financial year, then April-June would be quarter 1 and so on. We can use SWITCH in such scenarios:

We get the results below:

We used a formula here that would find the month number in the Dates column: if it’s month 1, it’s quarter 4; if it’s month 2, it’s quarter 4; if it’s month 3, it’s quarter 4; if it’s month 4, it’s quarter 1; and so on.

A few notes about the SWITCH Function

As the functions are limited to 254 arguments, we can use up to 126 pairs of value and result arguments.

#N/A error – Occurs when the SWITCH function is unable to match and there is no else argument. For example, for a value 7 and we give the formula =SWITCH(A3,1,”Sunday”,2,”Monday”,3,”Tuesday”), the function will return the #N/A error.

#NAME? error – Occurs if we edit a cell in a version of Excel that doesn’t include the SWITCH function.

Additional resources

Thanks for reading CFI’s guide to the Excel SWITCH function. By taking the time to learn and master Excel functions, you’ll significantly speed up your financial analysis. To learn more, check out these additional CFI resources:

Excel Functions for FinanceExcel for FinanceThis Excel for Finance guide will teach the top 10 formulas and functions you must know to be a great financial analyst in Excel. This guide has examples, screenshots and step by step instructions. In the end, download the free Excel template that includes all the finance functions covered in the tutorial

Advanced Excel Formulas You Must KnowAdvanced Excel Formulas Must KnowThese advanced Excel formulas are critical to know and will take your financial analysis skills to the next level. Advanced Excel functions you must know. Learn the top 10 Excel formulas every world-class financial analyst uses on a regular basis. These skills will improve your spreadsheet work in any career

Free Excel Tutorial

To master the art of Excel, check out CFI’s FREE Excel Crash Course, which teaches you how to become an Excel power user. Learn the most important formulas, functions, and shortcuts to become confident in your financial analysis.