Nested If formula with an AND condition

adrienne0914

Board Regular
Joined
Mar 22, 2018
Messages
73
Office Version
  1. 365
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:

[TABLE="width: 600"]
<tbody>[TR]
[TD]Company[/TD]
[TD="align: center"]FY 2017[/TD]
[TD="align: center"]YTD 2017[/TD]
[TD="align: center"]YTD 2018[/TD]
[TD="align: center"]Group[/TD]
[/TR]
[TR]
[TD]ABC Company[/TD]
[TD="align: center"]40[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]12[/TD]
[TD="align: center"]E[/TD]
[/TR]
[TR]
[TD]DEF Company[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]F[/TD]
[/TR]
[TR]
[TD]GHI Company[/TD]
[TD="align: center"]2,489[/TD]
[TD="align: center"]1,136[/TD]
[TD="align: center"]945[/TD]
[TD="align: center"]A[/TD]
[/TR]
[TR]
[TD]JKL Company[/TD]
[TD="align: center"]1,025[/TD]
[TD="align: center"]250[/TD]
[TD="align: center"]485[/TD]
[TD="align: center"]B[/TD]
[/TR]
[TR]
[TD]VH1 Company[/TD]
[TD="align: center"]536[/TD]
[TD="align: center"]169[/TD]
[TD="align: center"]101[/TD]
[TD="align: center"]C[/TD]
[/TR]
[TR]
[TD]CBS Company[/TD]
[TD="align: center"]155[/TD]
[TD="align: center"]75[/TD]
[TD="align: center"]77[/TD]
[TD="align: center"]D[/TD]
[/TR]
[TR]
[TD]DEC Company[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]0[/TD]
[TD="align: center"]11[/TD]
[TD="align: center"]F[/TD]
[/TR]
</tbody>[/TABLE]

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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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 :beerchug::beerchug:
 
Last edited:
Upvote 0
Cheers :beerchug: jproffer, I think since Excel 2007, you can nest up to 64 levels of IFs :eeek:
 
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,223,214
Messages
6,170,772
Members
452,353
Latest member
strainu

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