Alternative to nested IF structure (XL2013)

AOB

Well-known Member
Joined
Dec 15, 2010
Messages
660
Office Version
  1. 365
  2. 2016
  3. 2013
Platform
  1. Windows
Hi all,

I need a formula to "bucket" numerical values into groups / categories

Something along the following lines :

Age
Age Category
1
0 - 2
2
0 - 2
3
3 - 7
5
3 - 7
8
8 - 15
12
8 - 15
17
16 - 30
34
31 - 90
106
90+

<tbody>
</tbody>

















I can do this with a simple nested IF statement á la :

Code:
=IF(A2<3,"0 - 2",IF(A2<8,"3 - 7",IF(A2<16,"8 - 15",IF(A2<31,"16 - 30",IF(A2<91,"31 - 90","90+")))))

But I'm curious to see if there's a better, more efficient, method. I don't really like nested IFs; for a start, there's a limit on the number of IFs you can nest (is it 7?) but also they can be difficult to read and, well, I'd just like to learn a better way.

My initial thoughts were something along the lines of the SWITCH statement in Access, where you evaluate an arbitrary series of statements and return the output for the first statement which returns TRUE - which would be perfect here - but there doesn't seem to be an equivalent in Excel?

There's CHOOSE but with that, one would have to specify the return value for each possible input (i.e. 1, 2, 3,.....,X) rather than value ranges

Any other suggestions?

Thanks!

Al
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Thanks Saba - I can't open that link though - can you tell me what alternative native function you would recommend?
 
Upvote 0
Upvote 0
No problem

Organise the data as given below in A2:B7 (two columns)

Lookup table
00-2
33-7
88-15
1616-30
3131-90
9190+

<colgroup><col><col></colgroup><tbody>
</tbody>


Then

Use the following formula for approximate lookup (note TRUE is used instead of usual FALSE)

=VLOOKUP(D2,$A$2:$B$7,2,TRUE)

The following table starts from D2 as shown below and the formula is entered into E2 and copy it down.

AgeGroup
10-2
20-2
33-7
53-7
88-15
128-15
1716-30
3431-90
10690+

<colgroup><col><col></colgroup><tbody>
</tbody>

Please let me know if you have questions.
 
  • Like
Reactions: AOB
Upvote 0
Thank you Peter,

I am new here and just wanted to give the solution instead of writing it up.

I will follow the rule from now on.

Kind regards

Saba
 
Upvote 0
Thanks for the suggestion Saba - it's certainly more scalable than nested IFs although I'd prefer not to have to introduce new data to support the formula. I was more curious to see if it could be done via native Excel functions alone. But thanks for the suggestion!
 
Upvote 0
You can put the lookup table into the formula as a hardcoded array, but it's better practice to use a separate range for that data as it's much easier to maintain.
 
  • Like
Reactions: AOB
Upvote 0

Forum statistics

Threads
1,215,403
Messages
6,124,710
Members
449,182
Latest member
mrlanc20

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