Say Goodbye to IF Statements in Excel with SWITCH
HTML-код
- Опубликовано: 22 май 2024
- This tutorial will show how to use the SWITCH function in Microsoft Excel. We start by exploring the basics of the IF function, a staple in Excel's formula arsenal, to ensure a solid foundation. Then, we introduce the SWITCH function - a lesser-known yet incredibly potent tool in Excel. We'll compare these two functions side-by-side, illustrating how SWITCH can provide cleaner, more readable formulas, especially in scenarios with multiple conditions.
Key highlights of this video include:
A comprehensive overview of IF and SWITCH functions.
Practical examples demonstrating the advantages of SWITCH over nested IF statements.
Step-by-step guidance on how to implement the SWITCH function in real-world scenarios.
Tips for enhancing formula efficiency and readability in your Excel projects.
By the end of this tutorial, you'll be well-equipped to make the switch (pun intended!) from cumbersome IF statements to the elegant simplicity of the SWITCH function. Whether you're managing data, analyzing reports, or love to streamline your Excel workflows, this video is your gateway to next-level Excel proficiency.
See why XLOOKUP is Superior to SWITCH: • Why XLOOKUP Reigns Sup...
Practice File: go.teachers.tech/SWITCH_FUNCTION
Timestamps:
0:00 Introduction
0:20 Replacing a Nested IF statement with SWITCH
3:21 Using an Operation with the SWITCH function
5:30 Using an IF statement with a nested SWITCH function
I didn't know about this function. But after watching your video, I still prefer using tables with the xlookup-function to keep things as variable as possible.
How can you use XLOOKUP to insert values based on criteria in other cells? SWITCH has a different function it seems to me.
@@jmacdono You create a table with values that correspond to the translation. Consider the second example. You could create a separate table with a column for region and another column for the associated commission percentage. In the original table, you use xlookup to lookup the region and return the commission percentage. This approach is much easier to manage if the number of categories is large or likely to change.
@@jmacdono Microsoft's web site help is a great resource for all of Excel's functions. Heaven help you should buy one of the many books available.
Exactly what I tought while watching the video.
based on experience, i could say the same, using a table and xlookup is better as it is dynamic. works same way as a join in SQL, and it handles missing results much better.
I am the master of nested IF statements. You have ruined my life. Just kidding. This is great. I cannot wait to replace all of my nested IFs. Thank you.
you can use =IFS() as well so they don't have to be nested and it looks more like this switch statement
If statements are still needed in any situation where you test different data points. Cases where you have just one value to test are actually not as common as you'd think outside of simple demos.
Note for all german users: apperantly, in the german Version of Excel, this function is intuitively called "ERSTERWERT"
At 1:30 I realised this is the DECODE function in SQL. Super handy and I no longer need to do those awful nested IFs. Thank you
True “IF” is not handy in this situation, but you can use”IFS” function, same results and neat as much as switch. Thanks for the explanation, another function is added to the line, helpful.
That's true, but the only problem with "IFS" is you must have a value which is true. So if any value doesn't match any in the "IFS" statement the statement will fail.
@@alexk7467You can insert as last condition a ever-true one, so a condition without any restriction, simply ……;TRUE”;”Value you desire”). So if all the previous conditions fail, this one will apply
For that, you can encapsulate the function with IFNA or IFERROR :)@@alexk7467
@@alexk7467 You can set the final test value to "TRUE()" then the result: =IFS(test1, result1, test2, result2, ..., TRUE(), result_n)
@@alexk7467the very last statement in the IFS could just be 1 then set the default value.
Example:
ifs(case1, “A”, case2, “B”, case3, “C”, 1,””). If all cases fail, the default will be “”.
I always did a vlookup function with a table to change a number to a rating. Also, I find that it is still pretty clean to use 2 digits concat in another table to change a double input into a single output. The formulas are clean that way too. Still, I'm glad to know the switch function exists.
I use SWITCH it in Power Bi. I normally use IFS to avoid nested if statement. Great one!
Wow, this tutorial on using the SWITCH() function is incredibly helpful! I've always struggled with nested IF statements, but this alternative seems much more efficient and organized. Thanks for breaking it down step by step and providing clear examples. Can't wait to start implementing this in my own projects!
Using excel for decades but today I learned about switch. Thanks ❤
Thank you for this - I understand that this video is about the function switch. But for efficiency and future adjustments, I would put all the values into 1 or 2 tables and use the strengths of xlookup to return the desired results, instead of hardcoding it into a formula.
I would agree that.
@troelstrc Exactly.
In this example a simple table of corresponding data (Performance Score / Performance Rating) can be used for multiple purposes including the source for Data Validation List (i.e. the Performance Rating cell range as a drop-down menu) and in one's preferred Lookup formula.
Hard-coded data in formulae can be very restrictive, and make back-tracing errors and amendments very difficult. I avoid hard-coded data in formulae wherever possible.
This is an extremely helpful tutorial. Thank you so much for sharing it. You did a great job of laying out and explaining the material. Thank you, again!
I have not heard of the switch function...THAT was excellent! Thank you!
Thanks for this, I like the structure of the formula (more so than “IF” as simpler for those nested functions as you’ve also highlighted). As others have said I prefer reference tables and lookups for most instances but I will definitely use the “SWITCH” formula as have many use cases like dynamic formulas to work out year to date values.
Great to learn something new 👍🏾
You explain things very well and it's easy for me to learn from your videos despite my adhd. Thank you!
You’re welcome!
Actually, it is the equivalent of Select case in VBA. Thanks a lot, I did not know this function existed in Excel. It would have saved me a lot of time if I had known it sooner.
Thank you for this video. While I am known as the Excel genius at my work, I wasn't aware of the Switch function. I am sure I'll be able to have a lot of fun with this function in the future
It's easier, quicker and more dynamic to use vlookup (or xookup) or index/match to a reference table. For "No Rated", you can wrap your function in an IFERROR.
@@rlsbdog I don't think they have the exact same purpose. The lookups and index/match functions are referring to a singular cell. In one of my Excel-tables, I have a sumifs function in which I would want it to select another column based on the value of another cell. In this case, I think the switch function fits better.
@@Pronellyllon switch function is inflexible and undynamic
@@danguee1 it worked pretty well for me. In a situation where I used the IFS-function and continuously referred to the same cell had a specific value then needed to pick up a specific column in a table, I used the SWITCH-function instead. Now I didn't need to refer to the same cell anymore. Everything else in that formula stayed the same
I use Switch in PowerShell all the time, but funnily it never occurred to me that it exists in Excel.
Really useful, thanks!
switch is also available in many other programming languages
Hey! this is simpler than nested if function. THANK YOU!
That's very handy. I've neither used nor heard of this function, but I will likely make good use of it this week. There are a few fringe cases where I suspect it's no better (e.g., to simulate the output of a decision tree by examining TRUE/FALSE statements in multiple cells, which I think would require as many nested SWITCH functions as nested IF functions to achieve), and as others have said, larger lists are best queried using lookup functions, but this will tidy up smaller lists in my future spreadsheet work significantly.
Thank you RUclips algo! I actually can use this Monday at work... completely useful and relevant. Very nice examples!
Great to hear! Thanks!
Happy days! This is the honorable descendant of the CASE statement in good old FoxPro. Well done MS!
Wow what a time saver! Truly good by nested IFs lol thanks for sharing!!
Thank you very much. I didn't know about this formula but will definitely use it in the future.
Glad it was helpful!
This was amazingly useful! I have so many nested ifs in a budget spreadsheet, and it makes it so hard anytime I need to change things. Usong switch instead is going to make it so much easier! Thanks so much!
You're so welcome!
Great examples! I had never heard of switch.
Very helpful teacher. This is the 1st time I know about this function
Never heard of the Switch function. Thank you Jaime!!! :)
You're welcome!
Recently retired, worked with Excel for years and didn't know about switch. Looks very handy, can think of many times I would have chosen that instead of the clumsy "if" statements. Thanks.
I’m glad you found it useful!
SWITCH is a new function not find in older version of excell
@@tomjones1502 This function only in 365 right?
No, SWITCH function was added in year 2016, in excel 365
Switch function is in Excel 2019 and 365 (not sure but 2021)
Thank you for all of your help through the years!
You're very welcome!
Excellent. I already have a couple of work cases that can benefit from this SWITCH function!
Well explained! Thanks for sharing!
Hi ! Nice video. Very informative about Switch function. Honestly speaking I didn't knew about this until now. Thanks for sharing knowledge.
I read many comments below about usability of this function and suggestions about instead use xlookup, index match and other various function. They may be right in their opinion as xlookup, index are very powerfull. BUT, this tutorial is about Switch function and not about finding alternatives to if function or switch function. See, when these powerfull functions were not available we used to use if function very largely. But now with advancements in MS Excel we get so many new functions with mind blowing capability. It may so happen that one day there would be better function available then xlookup! Who knows. So I would stick to commenting on Switch function and its usability, quality of the video, quality of content of video like language and graphics used, explanation done, example shown and discussed rather then speaking of alternative to switch function.
Overall very interesting and informative video.
With the nested if like this, using a reference lookup table is ideal.
When I use if statement, I mostly use it as argument so the formula will do a different calc
Very interesting and well-presented. Thanks!
I've got dozens and dozens of spreadsheets with massively nested IF statements (up to about 12-times). Why didn't I know about this? Thanks again.
Thank You. This will make my sheets so less complicated now.
This is AWESOME!!!! Was able to simplify so so soooooo many IF statements in a spreadsheet I am working on.
Glad it was helpful!
So very helpful! Excellent presentation regarding a function I never heard of...
Glad it was helpful!
thank you for sharing the knowledge
Great function! Thanks a lot, I didn't know about this
Brilliant - Thanks for sharing. Really appreciate your work. Kind Regards
Thanks for the demo. I can see some scenarios where this could help.
Absolutely excellent info. I want to try it on some spreadsheets that have some complex nested if statements
Never used switch. Liked and subscribed. Good input.
I have not seen this function. Brilliant! TY
I love switch(). I told my analyst to try it a year ago and he cleaned up some complex sheets with it.
That's awesome!
Excellent, I shall using it. Thanks!
Love the new SWITCH function!
Thank you so much. I loved it.
Awesome Tutorial, so much easier.
Very useful! Thanks!
Great thank you lot Mrs Teacher's Tech
Excelent and very useful! Thanks
Very neat explanation sir💐🙏
Nice- I didn't know... Thanks
I create so many complicated spreads with very long IF statements, the switch function is going to cut my work in half. Thank you for sharing.
SWITCH is nice, but I'm more a fan of IFS. Nice video ❤🙏🏽
Awesome!
I'd gently suggest the next step would be to use lambda() to call the switch statements so that there's only one version of the switch floating around in the examples, rather than multiple copies.
Yes?
Yes, this would encourage me to use SWITCH. I really don't like having thousands of copies of the same formula with hard-coded values. The alternative is to write a VBA function (which I often do). Or go back to a standard VLOOKUP or INDEX(MATCH()).
I love the SWITCH function!!! =)
This helped alot thank you!!!
Knew of switch functions generally... Had no idea it was in Excel. How handy.
great, did not know about it, thanks for sharing!
I have been using Excel since 1995 and am always excited to learn new things.
For those saying rather use a lookup table - perhaps the example was a bad one.
There are many times when we DO use If statements and I can see the value of using SWITCH instead - it is much neater and clearer for editing later.
My only constructive feedback is that the title of this video is misleading. The 3rd example shows how IF statements still have value. 🙂
I use CHOOSE for similar situations, but this is useful too.
Like most reactions i would probably use xlookup and a table. I do see an advantage when you are using numbers and letters when searching. I will test the speed of switch vs xlookup on a large number of records. Thanks for the video!
ahhh saved so much time ! amazing!
It's good for Example 2 and 3 where the values are Text, but for Example 1 I would use CHOOSE, nested within an IFERROR statement to get the Not Rated result.
Excellent formula to save time
This is excellent
It may be useful for one-off small tables, but for anything larger or repeatable, I'd use the IFERROR and VLOOKUP functions and a separate tab with the reference data (using named ranges for the data areas). Doing that, I'd be able to add to the list of selection items very easily and the data in the entire table change without writing a really long cell formula nor having to update the cell formula once I needed to update my choice criteria.
👍excellent. Very useful. Thanks
Pretty cool. I didn't know about this one.
Never heard of this. Thanks for letting us know. (And for your other tips on other posts).
So glad you found useful! Your welcome.
Perfect, thank you
I just heard about it now. Thanks🌹
I've used "switch" coding in C for 40 years, but I didn't know Excel had that function. I don't know the maximum number of close brackets I've ever had in a nested IF formula, but at some point I usually opted to just switch to a custom VB function. This definitely simplifies things when comparing simple values. I'll have to dig a little deeper to see if it can be used to return a value using calculations/formulas as criteria.
Never heard of it before tbh. Looks useful.
Much clearer than using multiple in-line ifs. I hope the next MS step is to get away from inline functions to make it more readable and easier to debug.
Sir this is great
Never heard of it but will try it.
Thank you 😊
Nice function. I can use this. Will save a lot of hassles.
I'm guessing it's the same benefit as in other languages. Essentially, the runtime process only needs to access the variable once instead of during each conditional.
thank you sir ‼️👍
Thank you
Glad I could help!
Love it.
Extremely well explained and perfect real life examples
Thank you!
Avoid using a switch statement, try using if statement with a VLOOKUP or XLOOKUP already provides the values. Refrain from hard-coding in the formula, etc.
Why?
Because your values might change, and instead of changing a bunch of formulas, you change the lookup table once. For example, if Excellent changed to Outstanding, just update the reference table instead of all the formulas. You can also add IFNA at the beginning for a value that’s not found, a la “Not Rated”
@@JeffUmscheid I've got a lot yet to learn.
Dynamic ✅
You don't have to hard-coded the value. You can use name ranges for both the region values and commission values, to a certain degree of dynamic when using SWITCH().
This is an example with the commission values in named range. SWITCH(E1,"NORTH",C_NORTH,"SOUTH",C_SOUTH,"EAST",C_EAST,"WEST",C_WEST,C_DEFAULT)*D1
Brilluant. Would have saved me using hard to match brackets and nested if statements as well as vlookup.
you can also use ranges as your values and results, if you use TEXTJOIN("",TRUE,IFERROR(SWITCH(),"")) because the "" in IFERROR returns blanks for the errors, and TRUE in TEXTJOIN() ignores those blanks. For example: =TEXTJOIN("",TRUE,IFERROR(SWITCH(A6,L2:L6,M2:M6),""))
Thanks.
Terrific, very impressive!
Seeing as you know what you're talking about, and you make things very simple, I was just wondering if you could do a different video which I haven't found anywhere. This deals with inventory and sales, where each item has multiple colors.
It would be great to show how to subtract a certain color from the inventory when a sale is made in the sales tab without listing each item multiple times per item.
Just a suggestion. 😇
What an excellent video!
For me I only use switch when a vlookup table won't do the job (like when a default is required). The reason for this is a vlookup table lets you put all of the values on the sheet, instead of in a function and other formulas can use the same values. I tend to make a named reference for anything that's in a vlookup too, so I know not do delete it by mistake and having it easily available in any sheet :)
With XLOOKUP you have a default - to me, the SWITCH function looks pretty useless. What I'd like to have would be a CASE function - CASE(expression1, value1, expression2, value2, ..., default_value)
@@brdrnda3805 I believe the SWITCH() is the same as CASE().
@@laurencesyeng6182 Just compare Excel's SWITCH function with the CASE statement proposed by me. It's different.
Thanks for sharing. Interestingly, "CHOOSE" might be another option for the first example... =IFERROR(CHOOSE(C12,"Poor","Below Average","Excellent","Good","Excellent"),"Not Rated")
Em português essa função é chamada de PARÂMETRO. Excelente!
Great tip, never heard of Switch. Seems like the list values need to be plugged in manually...any way to reference to the values held in a table?
Interesting and useful
Very useful...
Didn't know about the switch, thank you, but would also not use it in these instances as it just causes more maintenance work later on. Some reference table / lookup will make it much easier to maintain if situations change.