Nested If formula with an AND condition

adrienne0914

Board Regular
Joined
Mar 22, 2018
Messages
57
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I'm trying to group data based on volume. I'm grouping as follows:
A: >2000
B: 1000-2000
C: 500-999
D: 100-499
E: 1-99​

It looks like this:

CompanyFY 2017YTD 2017YTD 2018Group
ABC Company401212E
DEF Company000F
GHI Company2,4891,136945A
JKL Company1,025250485B
VH1 Company536169101C
CBS Company1557577D
DEC Company0011F

<tbody>
</tbody>

My formula is:
=IF(B2>2000,"A",IF(B2>=1000,"B",IF(B2>=500,"C",IF(B2>=100,"D",IF(B2>0,"E", IF(B2=0,"F",IF(D2=0,"F")))))))

I'm trying to weed out the ones with no activity in 2017 or 2018, making them group F. The way my formula reads now, it assigns group F if B or D equal 0. I don't want DEC Company to be F because there was an increase in activity from 2017 to 2018.

I want the formula to assign group F if B AND D equal 0. Not sure how to insert an AND formula.

Thanks in advance!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
PHP:
=IF(B2>2000,"A",IF(B2>=1000,"B",IF(B2>=500,"C",IF(B2>=100,"D",IF(B2>0,"E", IF(AND(B2=0,D2=0),"F","ALL FALSE"))))))

Not sure if I counted the parenthesis right...

You should never see "ALL FALSE", but I had to put something there :) . If you want, change it to "" (nothing).
 
Last edited:
Upvote 0
PHP:
=IF(B2>2000,"A",IF(B2>=1000,"B",IF(B2>=500,"C",IF(B2>=100,"D",IF(B2>0,"E", IF(AND(B2=0,D2=0),"F","ALL FALSE"))))))

Not sure if I counted the parenthesis right...

You should never see "ALL FALSE", but I had to put something there :) . If you want, change it to "" (nothing).

Hi jproffer! You had the parentheses right. This worked like a charm. BUT now I realize I need something slightly different. I don't want to have blanks in any cells. So is there a way to modify the formula so that it assigns a value based on D2 if it is greater than 0 and B2 is 0?
 
Upvote 0
Sure...try this one:

PHP:
=IF(B2>2000,"A",IF(B2>=1000,"B",IF(B2>=500,"C",IF(B2>=100,"D",IF(B2>0,"E",IF(AND(B2=0,D2>0),D2,IF(AND(B2=0,D2=0),"F","")))))))
 
Upvote 0
Sure...try this one:

PHP:
=IF(B2>2000,"A",IF(B2>=1000,"B",IF(B2>=500,"C",IF(B2>=100,"D",IF(B2>0,"E",IF(AND(B2=0,D2>0),D2,IF(AND(B2=0,D2=0),"F","")))))))

Thanks again! It's assigning the value of D rather than giving it a ranking. I want it to look at D, and assign a group based on that number. So for DEC Company above, the ranking would be E since it's 11. That may be too much nesting for this formula, no?
 
Upvote 0
Ohhhhh, I thought you wanted the value OF D if B was empty....sorry. Not sure if it's too many ifs or not, I doubt it...give me a few :)
 
Upvote 0
Hi,

Sorry jproffer for stepping in, think that's going to be a "bunch" of IFs, here's my suggestion.

E2 formula uses Table G1:I6 (when your parameters change, just change it in the table).
F2 formula has Table hardcoded (when your parameters change, you'll have to update the formula, but you don't need G1:I6).


Book1
ABCDEFGHI
1CompanyFY 2017YTD 2017YTD 2018GroupGroup00F
2ABC Company401212EE199E
3DEF Company000FF100499D
4GHI Company2,4891,136945AA500999C
5JKL Company1,025250485BB10002000B
6VH1 Company536169101CC2001A
7CBS Company1557577DD
8DEC Company0011EE
Sheet69
Cell Formulas
RangeFormula
E2=LOOKUP(IF(B2=0,D2,B2),G$1:G$6,I$1:I$6)
F2=LOOKUP(IF(B2=0,D2,B2),{0,1,100,500,1000,2001},{"F","E","D","C","B","A"})


Either way, formula copied down.
 
Upvote 0
I think this is what you want...and it wasn't too many nested IFs in Excel 16

PHP:
=IF(AND(B2=0,D2=0),"F",IF(SUM(B2,D2)<>D2,IF(B2>2000,"A",IF(B2>1000,"B",IF(B2>500,"C",IF(B2>100,"D",IF(B2>0,"E"))))),IF(D2>2000,"A",IF(D2>1000,"B",IF(D2>500,"C",IF(D2>100,"D",IF(D2>0,"E","")))))))

Don't be sorry at all. I like it...it was indeed a bunch of IFs...yours is MUCH shorter (y)(y)
 
Last edited:
Upvote 0
Cheers (y) jproffer, I think since Excel 2007, you can nest up to 64 levels of IFs :eek:
 
Upvote 0
I wasn't sure of the number. I was thinking it was 7 before 2007 version, and I had heard they raised it (finally lol), but wasn't sure how far they raised it.
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,605
Members
449,089
Latest member
Motoracer88

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