How to use the SWITCH function in Excel 2016
If you've spent too much time creating a nested IF formula, you'll love to use the new SWITCH function in Excel. This function saves you time in situations where IFS is needed.
If you've spent too much time creating a nested IF formula (IFS function), you'll love to use the new SWITCH function in Excel. This function saves you time in situations where IFS is needed. Earlier this function was only available in VBA, but recently SWITCH was added in Excel 2016, Excel Online and Mobile, Excel for computers and Android phones. This article will show you how to use the SWITCH function in Excel 2016.
- MS Excel - Lesson 15: Harness the power of the Excel function in Excel
SWITCH function syntax
The SWITCH function compares an expression with a list of values and returns the result in the first matching value. If no match is found, it can return the default value.
The structure of SWITCH function is as follows:
SWITCH (expression, value1, result1, [default or value2, result2], . [default or value3, result3])
It has 4 arguments, one of which is optional:
- Expression (expression) is a required argument used to compare value1 . value 126.
- ValueN is a value used to compare expressions.
- ResultN is the value returned when the corresponding valueN argument matches the expression. It must be specified for each valueN argument.
- Default is the value returned if no match is found in the valueN expressions. This argument has no corresponding resultN expression and must be the last argument in the function.
Because functions are limited to 254 arguments, you can use up to 126 pairs of value arguments and results.
Compare SWITCH function with IFS function
The SWITCH function, as well as the IFS function, helps define a range of conditions. However, with the SWITCH function you can define an expression and a sequence of values and results, not some conditional statements. With the SWITCH function, you do not need to repeat the expressions again as in the IFS function.
For example, the IFS function below finds the exact states.
Explanation: cell A2 contains the 85-UT string. RIGHT function extracts the 2 rightmost characters from this string (UT). As a result, the IFS function returns to the right state (Utah). If the rightmost two characters are not equal to UT, TX or OH, the IFS function returns a question mark. Instead of TRUE, you can also use 1 = 1 or something else that is always TRUE.
The SWITCH function below produces identical results but is much easier to read.
Explanation: if the first argument (RIGHT (A2.2) in this example) is in UT, the SWITCH function returns Uta; if TX returns to Texas; If OH returns to Ohio. The final argument (question mark in this example) is always the default value (if no match is found).
Similarly, you can see the following example with the rating system, the SWITCH function looks more compact.
See how the SWITCH function works when combined with other functions. Suppose, we have a few days and want to see it quickly is today, yesterday or tomorrow. To do this, we will use the TODAY function to return the serial number of the current day and the DAYS function returns the number of days between two dates.
You can see the SWITCH function works perfectly for this task.
With the IF function, conversion needs some integration and complexity. So you will be more likely to make mistakes.
However, it is not always possible to use the SWITCH function in Excel. There are many examples where you cannot use the SWITCH function instead of the IFS function.
Explain: because here the "<=" and ">" symbols are used in this IFS function, you cannot use the SWITCH function.
The SWITCH function is really a useful function, which saves time and makes fewer mistakes.
I wish you all success!
See more:
- These are the most basic functions in Excel that you need to understand
- How to combine Sumif and Vlookup functions in Excel
- How to use the SUM function to calculate totals in Excel
You should read it
- How to use the IFS function in Excel 2016
- Save time with these text formatting functions in Microsoft Excel
- DAY function in SQL Server
- MIN function in SQL Server
- MAX function in SQL Server
- Function in programming C
- How to use the SUM function to calculate totals in Excel
- SUM function in SQL Server
- The ord () function in Python
- ABS function in SQL Server
- RIGHT function in SQL Server
- How to use Hlookup function on Excel
Maybe you are interested
We may be able to see the 'second moon' in the sky with the naked eye next May How to Install PHPMailer The most remote and least-populated places on Earth Will the Earth be affected if the comet once destroyed the dinosaurs hitting the Sun? 'Wow!' - Has the mysterious cosmic signal of 'alien' been decoded? True moon, snow moon and comet will appear together today