Using the Switch function to return Employment tenure

bearcub

Well-known Member
Joined
May 18, 2005
Messages
731
Office Version
  1. 365
  2. 2013
  3. 2010
  4. 2007
Platform
  1. Windows
I am trying to learn the new excel functions and one them I don't totally understand is the Switch function.

We want to classify the length of time a rep has been with the company by putting them in the follow buckets:

1719534253672.png



Here is the formula we are presently using to put them in those buckets and I thought their should a more efficient way of doing this. If there is, can I use an array function to replace the following nested IF formula:

IF(J3>4,"4+ YRS",IF(J3<1,"0-1 YRS",IF(AND(J3>1,J3<2),"1-2 YRS","2-4 YRS")))

This is the result section. Is there an array formula or more efficient function to use other than the IF function

1719533824668.png
 

Attachments

  • 1719533793098.png
    1719533793098.png
    8.2 KB · Views: 4

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
try

with SWITCH
Excel Formula:
=SWITCH(TRUE,J3>4,"4+ YRS",J3<1,"0-1 YRS",AND(J3>1,J3<2),"1-2 YRS","2-4 YRS")

with IFS
Excel Formula:
=IFERROR(IFS(J3>4,"4+ YRS",J3<1,"0-1 YRS",AND(J3>1,J3<2),"1-2 YRS"),"2-4 YRS")


1719538286716.png
 

Attachments

  • 1719538227819.png
    1719538227819.png
    59.7 KB · Views: 3
Upvote 0
to avoid IF / Switch Funtions

try Lookup, but its need table ( Cell S3:T7 )

Excel Formula:
=LOOKUP(J3,$S$3:$T$7)

1719539102202.png
 
Upvote 1
Solution
When using grouping logic, I am also a fan of using a lookup table as in @SunnyAlv's 2nd example, although I probably would use VLookup.
If you are using "If statement" style logic, if you put the arguments in descending order there should be no reason to use AND (for between) in the logic and just rely on the conditions being evaluate from left to right. eg
Excel Formula:
=IF(J3>=4,"4+ YRS",IF(J3>=2,"2-4 YRS",IF(J3>=1,"1-2 YRS","0-1 YRS")))
Excel Formula:
=IFS(J3>=4,"4+ YRS",J3>=2,"2-4 YRS",J3>=1,"1-2 YRS",TRUE,"0-1 YRS")
Note: I have used >=, swap that for > depending on which bucket you want the cutover numbers 1,2,4 to fall into.
Although its possible as Sunny has demonstrated you won't see too many people using Switch for this type of scenario.
Switch is aimed at exact matches, so if you want to use ">" you using a workaround when you are using Switch to make it work.
The comparison is talked about here towards the bottom:
The Switch function is described here:
 
Upvote 1
Thank you both for the formulas - both work great. You were right about replacing the equal sign with >=.
 
Upvote 0

Forum statistics

Threads
1,221,813
Messages
6,162,117
Members
451,743
Latest member
matt3388

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top