How to Use the SWITCH Function in Excel

Excel

https://www.howtogeek.com/how-to-use-the-switch-function-in-excel

Excel’s SWITCH is a logical function that is primarily used for data manipulation. It evaluates an expression against a list of values, and returns a result corresponding to the first matching value.

Its popularity comes from its relative simplicity compared to other Excel functions that perform similar tasks, meaning it’s easier to read the formula and debug any issues.

In this guide, I’ll explain how to use the function with a real-world example, assess its benefits over other functions, and cover some of its limitations.

Microsoft added the SWITCH function to Excel in 2016, so it’s unavailable in earlier versions. If you try to use SWITCH in an incompatible version, Excel will return the #NAME? error .

The Syntax for SWITCH

Before I show you a real-life example of SWITCH in action, let’s look at the syntax:

=SWITCH(e,v1,r1,v2,r2,d)

where

  • e is the expression (the value that will be evaluated),
  • v1 is the first value to be compared against the expression,
  • r1 is the result that will be returned if v1 matches e,
  • v2 is the second value to be compared against the expression,
  • r2 is the result that will be returned if v2 matches e, and
  • (optional) is the default value if e does not match any of the v values.

While there are only two vpairings shown here in the syntax (v1r1 and v2r2), you can have up to 126 pairings overall. Given that SWITCH returns a result corresponding to the first matching value, it’s important to carefully consider the order of your vpairings.

If you do not include the optional d , and none of the values ( v# ) matches the expression ( e ), Excel will return the #N/A error .

SWITCH in Action

Let me show you the SWITCH function in a real-world scenario. In this table, I have a list of students and their grades, and I need to work out their next steps based on those grades.

An Excel table containing student IDs, their grades, and an empty column headed Next Step.

Since there are three different grade possibilities (A, B, and C), I need to incorporate all of these into the SWITCH formula. So, in cell C2, I will type

=SWITCH([@Grade],"A","Automatically advance to next level","B","Continue at this level","C","Move down to previous level","GRADE REQUIRED")

If any of the values or results in your SWITCH formula are not numerical, you need to surround them with quotes.

Although this looks complicated at first, when broken down, it’s actually quite logical:

  • First, I want Excel to evaluate the expressions in the Grade column of my formatted table, which is why I typed [@Grade] as value e.
  • Then, I have three vpairings: “A” will return “Automatically advance to next level,” “B” will return “Continue at this level,” and “C” will return “Move down to previous level.”
  • Finally, after the final pairing, I have stated “GRADE REQUIRED” as value d, which is the result if none of the values (v#) matches the expression (e).

After pressing Enter, because my data is in a formatted Excel table, the rest of column C will populate automatically.

An Excel table containing student IDs, their grades, and a Next Step column completed using the SWITCH function.

Notice how cell C8 contains “GRADE REQUIRED,” because the expression in cell B8 did not match any of the values in my SWITCH formula.

If I wanted to change the outputs in column C, I would head back to cell C2, amend the formula in the formula bar, and press Enter. This change would then apply automatically to the other cells in column C.

Why Use SWITCH Instead of IF, IFS, or XLOOKUP?

You may be wondering why you would use SWITCH over some of Excel’s other functions that perform similar actions, such as IFIFS, and XLOOKUP. Here are some reasons:

Avoid Repeating the Expression

To create the same results in the table above using IF or IFS, I would have to repeat the expression each time:

=IFS([@Grade]="A","Automatically advance to next level",[@Grade]="B","Continue at this level",[@Grade]="C","Move down to previous level")

With the SWITCH function, however, I only have to state the expression once at the start of the formula:

=SWITCH([@Grade],"A","Automatically advance to next level","B","Continue at this level","C","Move down to previous level","GRADE REQUIRED")

As a result, the SWITCH function is easier to read, less prone to typing errors, and easier to review if there’s an issue.

Keep Everything in One Place

Much like SWITCH, the XLOOKUP function compares an expression to a list of values, and returns a corresponding value. However, with XLOOKUP, the list of values is in a separate table, whereas SWITCH incorporates them all into one formula. This means that you don’t have any floating data, and so, your Excel spreadsheet stays tidy.

One Set of Parentheses

If I chose to use nested IF functions to achieve the same outcomes in the table above, I would have had to use a new set of parentheses for each IF argument:

=IF([@Grade]="A","Automatically advance to next level",IF([@Grade]="B","Continue at this level",IF([@Grade]="C","Move down to previous level","GRADE REQUIRED")))

As a result, the formula ends confusingly with three closing parentheses, and debugging any issues with the syntax would be more challenging. On the other hand, when used at its most basic level without any other additional functions, SWITCH requires only one pair of parentheses.

SWITCH Drawbacks

While SWITCH has many benefits, there are a few limitations to bear in mind before you get working on your Excel spreadsheet:

  • You can’t use operators (such as < or >) or approximate matches with the standard SWITCH syntax. Instead, SWITCH is limited to exact matching only.
  • If you have lots of potential values and results, constructing your SWITCH formula in the first instance will take forever. Personally, I would recommend using no more than seven or eight value-result pairings in your SWITCH formula.
  • SWITCH is a relatively inflexible function. For example, XLOOKUP can return entire rows and columns of data, rather than just a single value.
  • Because SWITCH requires lots of commas (and quotes if you’re including non-numerical values), it’s easy to make a mistake if you type the formula manually.

SWITCH is just one of the many different ways to use data in an Excel table. You might also consider using INDEX to find valuesMATCH to find a value’s position, or INDEX and MATCH together to create a two-way lookup.

Excel consulting ; Excel Consulting – Consultoria em Excel e Office 365

Partilhar:

Mais publicações

Excel; Excel consulting; Powerapss

What’s New in Excel (February 2025)

Excel Consulting.
Welcome to the February 2025 update. We are excited to announce that Copilot in Excel with Python is now available on Windows platforms for all enterprise and consumer users. Also starting now, Excel users on Windows and web can get to Copilot faster from anywhere on the grid. Furthermore, Copilot can now bring web and organizational data into your spreadsheets—available for Windows and Mac Insider users.

Excel

Excel’s 12 Number Format Options and How They Affect Your Data

Using Excel’s number format tool means you can ensure your spreadsheet both looks the part and handles your data exactly how you want it to. In this article, I’ll explain what each number format is, how to use it, and how it affects your data.

Things to Know Before You Start

Each cell has its own number format, which you can see by selecting a cell and seeing the Number group in the Home tab on the ribbon.

Excel

What’s New in Excel (January 2025)

Welcome to the January 2025 update. We are excited to announce that Copilot is now available to Microsoft 365 Personal and Family subscribers in most markets worldwide.
Also, this month, expanded text analysis tools with Copilot in Excel, focus cell for Windows and Mac users, and dark mode now available to Windows Insiders users.

Excel Consulting Image Blog

Microsoft Excel Finally Has a Dark Mode on Windows

https://www.howtogeek.com/microsoft-excel-dark-mode-windows A long-awaited display feature of Microsoft Excel has finally arrived—Dark Mode. You can now work on your spreadsheets with a darker theme on Windows PCs. As far as modern technological trends go, Dark Mode is certainly towards the top of the list. Indeed, it seems that every platform and program—from Google Chrome and Microsoft Edge to YouTube and Wikipedia—offers the option to switch from a white background to a black one. But there’s good reason to opt for this visual transition. Dark mode supposedly helps to reduce eye strain, often requires less battery power, is more favorable to individuals with light sensitivity, and projects a modernized, appealing appearance. Now, Microsoft Excel has joined the list, with the new feature allowing you to darken your entire worksheet, including the menu ribbon and even the cells themselves. If the darkened user interface concept is new to you, it’ll take some getting used to—but it’s worth giving it a try. People who have made the switch in Microsoft Word say that Dark Mode is now their default setting. This display change comes just a few months after Microsoft added Focus Cell—another visualization aid that lets you track the active row and column more easily—to its popular spreadsheet program. To enable Dark Mode, click “Switch Modes” in the View tab on the ribbon. In its blog announcement post, Microsoft added, “To make sure you are using a supported Office theme, select File > Account > Office Theme, and confirm that either Black or Use System Setting is selected.” It went on to clarify, “If you select the Use System Settings option, you will also need to make sure that your Windows theme is set to Black.” When you enable Dark Mode in Microsoft Excel, it won’t affect how others see the spreadsheet if you collaborate in real time or share it via OneDrive or email. Similarly, using Dark Mode on your desktop won’t automatically turn it on when you view the spreadsheet on your phone. In fact, this feature is currently only available in Excel for Windows to Microsoft 365 Insider members on the Beta Channel running Version 2502 (Build 18508.20000) or later. However, as with most Microsoft 365 features in their testing phase, Dark Mode will likely become generally available once Microsoft has verified its effectiveness and ensured its performance and positive user feedback. Whether Excel for the web, Excel for Mac, or the Excel mobile app eventually adopt this new feature remains to be seen. Excel consulting ; Excel Consulting – Consultoria em Excel e Office 365

© 2024 Created by wpexperts.pt