***************

Following up on last week’s introductory post on using the IF function, here’s one on how to use Excel’s IF statement when you have multiple conditions to meet.

The original question I received from a reader, which prompted this series, was about how to use the IF statement in Excel when you had two conditions that had to be met. For example, when sales fell between a minimum and maximum number. Let’s take a look at our example again. Note that I’ve added the maximum amount of $200K into cell B3:

Before we go further, if you’d like to work through the examples yourself, here’s the raw data you can copy into an Excel worksheet. First, open up a blank excel worksheet. Next, highlight the table below. Copy it, and then go back to your excel worksheet. Go to cell A1 (or another empty cell, if you want to put the data elsewhere), and then select “Edit” from the menu bar. Select “Paste Special” and then “Text” from the popup box. Click “OK”. The data should appear in your Excel worksheet just as it does above.

Bonus | 12% | |

Minimum amount | 100000 | |

Maximum amount | 200000 | |

Sales | Bonus | |

Salesman A | 87925 | |

Salesman B | 100000 | |

Salesman C | 145000 | |

Salesman D | 200750 | |

Salesman E | 178650 | |

Salesman F | 99555 | |

Salesman G | 147000 | |

Salesman H | 213450 | |

Salesman I | 122680 | |

Salesman J | 92500 |

Ok, now back to the tutorial.

Now, let’s suppose sales have to be greater than or equal to $100K **and** less than $200K for a salesman to receive a 12% commission rather than just be greater than $100K, as in our introductory example. How would you write that in “Excel-speak”?

It turns out that you can use Excel’s AND function, which Excel calls a logical operator (just like it calls the IF function). And, as usual, unlike how most other programming languages work, the syntax required in Excel is a bit different. To use it correctly, you have to write it like the following:

**=AND(first condition, second condition, …, etc.)**

(In other programming languages, AND would fall in between each condition, just like how we normally talk, but not in Excel!)

Let’s go back to the concrete example. To write the condition that sales have to fall betwen $100K and $200K for the salesman to receive a 12% commission, we’d write the following in cell C6:

**=IF(AND(B6>=$B$2, B6<$B$3),B6*$B$1,"No bonus")**

Like this:

Translated into plain English, our IF statement now reads, “If B6 is greater than or equal to B2 **and** B6 is less than B3, then multiply B6 by B1. If not, then put ‘No bonus’ into the cell.” In the first case, our salesman didn’t meet the $100K requirement, so the AND function returned a false, so the IF statement put “No bonus” into the cell. By the way, in our case, we only had two conditions to meet, but if we had more, we could just keep adding them into the list of conditions in the parenthese after the AND function.

Here’s how the results look if we do this for all the salesmen in our example:

There are two other logical functions, OR and NOT, which work the exact same way:

**=OR(first condition, second condition, …, etc.)**

**=NOT(first condition, second condition, …, etc.)**

For example, we could actually rewrite our IF statement above using the OR condition if we’re careful. Here’s how it would look:

**=IF(OR(B6<$B$2,B6>=$B$3),”No bonus”, B6*$B$1)**

Like this:

Again, in plain English, what we’re saying is, “If B6 is less than B2 **or** B6 is greater than or equal to B3, put ‘No bonus’ into the cell. Otherwise, multiply B6 by B1.” We’re basically testing for the opposite conditions in our OR statement as we did in our AND statement. And you’ll get the same results as above with the AND statement, as seen below:

You might be able to picture now how you could start using multiple AND, OR, and IF statements nested altogether to test all sorts of complicated conditions in Excel. But keep in mind that cells in Excel are really meant more for doing calculations than programming, which is really what you’re getting into once you start putting in complex IF statements. (I’ve read somewhere you can nest up to 7 IF statements in Excel, though I’m not sure to which version(s) of Excel that limitation applies.)

In particular, coming up with a correct list of conditions to test for, in the right order, that don’t result in a false positive test (e.g. a condition accidentally being met that you didn’t mean to) is a big concern in Excel. The other problem is usability. Even if you were able to come up with a complex IF statement that did what you wanted it to, imagine you put the spreadsheet away and revisited it again in a year’s time when you had to update annual sales figures and calculate bonuses again. Here’s an example of a complicated nested IF statement with no other logical operators:

**=IF(A1<20, A1*1, IF(A1<50, A1*2, IF(A1<100, A1*3, A1*4)))**

Think about it: would you *really* want to spend an extra hour or two decoding that and figure out what you needed to change or update a year later? Similarly, if you had to use a worksheet that someone else wrote that contained a bunch of complicated IF statements, wouldn’t you go nuts? I would!

The statement above is actually even in “reverse” order of what you might normally expect. (In case you’re wondering, I pulled this example from the bottom of a webpage here. It provides the original reader’s question, though why he or she wanted to calculate that, I’m not sure!)

I’ll follow up this post with one on conditional formatting, and I’ve had a request to explain VLOOKUP, HLOOKUP, and pivot tables. Feel free to suggest other tutorials you’d like to see, and I’ll try my best to get to them!

***************************************************

**Look Good at Work and Become Indispensable Become an Excel Pro and Impress Your Boss**

***************************************************

## Ibaad ul Rehman

“I have to compare 2 dates ( one is current date and other date can either old date/future/current date), Current date will be standard date and then have to apply this query-If difference between 2 dates is: More than 3.5 days passed -show “Red”” in next column

if difference between 2 dates is :1 to 3.5 days passed-show “Orange”

if difference between 2 dates is: 0 to 3.5 days remaining show “blue”

if difference is more than 3.5 days remaining then show “green” in next column.

Thanks in advance

## Udayanga Siriwardana

i want to get the result in weekdays( Sunday,Monday,Tuesday,etc….), if Friday=”Monday Realize”,”Next Day”, and Saturday or Sunday=”Tuesday Realize” IN MS EXCEL

## SBaral

Thank u For providing example.

would u Please send me some excell example in mail..

if possible.

thank u

## Tony

Hi, how do I combine the two formulas below in the one cell? it’s been doing my head in, I’ve tried so many formulas from the web without success.

=IF(COUNTIF(G18:K18,”s”),”Suspended”,””)

=IF(COUNTIF(G18:K18,”w”),”Withdrawn”,””)

Basically I want cell F18 to display either:

“Suspended” if cells G18:K18 show an “s” in any cell, or:

display “Withdrawn” if cells G18:K18 show a “w” in any of those cells.

Otherwise, it would display blank, “”.

Please help, it would be much appreciated.

thanks,

Tony

## Annie

I need assistance please with writing an if/and/then statement to return a value as shown below:

if A1109973 and153962 and <=175956,660

otherwise 440

## Annie

Wait that’s not what I wanted. This is what I need help with putting into an if/then/and statement –

if A1 is less than 109973 then 1320

but if A1 is greater than 109973 but less than 131967 then 1100

but if A1 is greater than 131967 but less than 153962 then 660

if A1 is greater than 153962 then 440

## Sarthak Singla

Try this:

=LOOKUP(A1,{0,0;109973,”1320″;131967,”1100″;153962,”660″;”440″})

## Sarthak Singla

Or even this might work:

=IF(AND(A1>0,A1109973,A1131967,A1153962,440))))

## Abhishek

I have two sheets

Sheet1col1,Sheet1col2,Sheet1col3

Hr circle Count

Sheet2col1,Sheet2col2,Sheet2col3

Hr circle Count

Now i want the result :

If Sheet1col1=Sheet2col1 and Sheet1col2=Sheet2col2 then Sheet1col3+Sheet2col3

else Sheet1col3

## John S

I would like to compute Accuracy as a percentage by comparing an “estimated” forecast with “actual” results. For example:

Cell A1 is an estimate of unit production for the week.

Cell A2 is the actual production for the week.

Cell A3 = A2/A1 as a percentage.

I would like A3 to show:

0% if both A1 and A2 are = 0.

Or,

The calculated percentage if both A1 and A2 are > than 0.

Or,

A “string” or large value such as 999% if A1 = 0 but A2 > 0.

I can accomplish the first 2 of these results using an IF(AND) statement, but don’t know how to incorporate another IF or AND to also have the 3rd result present.

## Keith Carroll

Annie: I too wanted basically what you were wanting to be able to calculate commissions. So what I did was I created a formula in a few different cells which then was calculated in another cell to get me the result I want. I want it so that way if it is above a specific amount, then they cap out at that amount, and if it’s less than calculate that amount. If they don’t hit the minimum, then no bonus. So in line with the examples above, I put in the cells next to it, the following; =IF(B6>$B$3,$B$3,0)*$B$1, then in the next cell, =IF(AND(B6>$B$2,B6<$B$3),B6*$B$1,0), and then in the next cell is the final calculation, =IF(SUM(D6:E6)=0,"No Bonus",SUM(D6:E6)). This makes it a little longer, but as I was trying to put it all in one formula, I kept getting errors, so I split it up and then hid the cells that had the calculations.

For your direct questions though, I would do the following next to the cells in question, =SUM(C6:F6) to show the sum, =IF(A6$A$1,A6$A$2,A6$A$3,$B$4,0) to calculate greater than. This is a little more drawn out, but it works and gets the job done without any errors, or banging of the noggin.

## Keith Carroll

Sarthak Singla, the lookup function should be used when you are trying to look up a specific value for a specific item, as in; if I want the price of a specific product in A1, it would be pull the product up (preferably from a drop down menu to enable proper spelling), then the item number and so on, not when trying to calculate items between a specific number.

## S Sealy

Hi I am trying to write an IF formula to calculate residential water rates using the following rate blocs:

$2.48 per m3 (0-8 m3);

$3.10 per m3 (9-20 m3);

$4.66 per m3 (21-40 m3) and

$7.78 per m3 (over 40 m3)

but I am not getting it worked out. Can you please help me. Thanks.

## joe

@S Sealy

A28 – Cost $

B28 – M3

C28 – $ per M3

A28 =IF(B28=9,B28=21,B2841,SUM(B28*7.7),””))))

B28 = number of m3

C28 = =IF(B28=9,B28=21,B2841,”$7.70″,””))))

## joe

This website is shit, it botches your comments.

## MikeS

Thanks for clearing thatup. Much obliged.

## Francine Gabbard

Im trying to calculate PTO:

If ee type is part-time- 0 pto

=IF(F$8=”part-Time”,0)

Set up- years worked Col D$2, D$3, D$4

D$2- 0 year- zero PTO

D$3- 1 years- after 1 year 5 days

D$4- 10 years- after 10 years 10 days

Data-Years worked… Col B

=IF(B11=D$3,5)+IF( B11>=D$4,10)

I cannot get this to work correctly- help

## S Sealy

Thanks Joe for your input but I think your second comment brought some clarity since i do not understand your calculation. Please try to upload it as it should be again.

## Steve

Trying to take old customers out of my Excel file. I have file sorted in Customer name (column B) and then by Date of order (column G), and there are multiple orders by customers.

Customer name is in B2

Date of the order is in G2

So I tried this statement:

=(IF(B2=B1,””,IF(YEAR(G2)<=2020,"delete",""))

That worked for the first customer record but the next customer record returned a blank.

So I tried this statement:

=IF(AND(B9=B8,YEAR(G9)<=2010),"delete","")

That works but not the first record, the subsequent records it returns "delete".

How do I get it to properly mark all the records of the customer who has not placed an order since 2010?

Thanks!

## Karl

I required an IF OR statement where I had a long column of towns in my state (100s) and needed to flag those that were in our sales area.

I initially wrote:

=IF(OR(S:S=”Town1″,”Town2″,”Town3″,”etc…”),”Y”,””)

Turns out it needed to be:

=IF(OR(S:S=”Town1″,S:S=”Town2″,”S:S=”Town3″,”etc….”),”Y”,””)

Just curious as to why my original attempt isn’t adequate and had to put the column reference before each town?

Very interested to hear the answer

## ranit mehta

there is Invoice date is 24/05/2016 amount Rs. 500000/- and collection date is 30/05/2016 Rs.300000/- calculate additional discount 2.5% on 7days 2% on 5days

## ranit mehta

I want to know about debtors ageing formula how to calculate invoice date ageing.

## ranit mehta

Date Debit Credit Balance

24-May-16 652358.00 652358.00 Dr

25-May-16 1251215 652358.00 Dr

26-May-16 252141.00 904499.00 Dr

27-May-16 600000.00 304499.00 Dr

28-May-16 304499.00 Dr

29-May-16 304499.00 Dr

30-May-16 304499.00 Dr

31-May-16 695208.00 999707.00 Dr

1-Jun-16 999707.00 Dr

2-Jun-16 999707.00 Dr

3-Jun-16 999707.00 Dr

4-Jun-16 300000.00 699707.00 Dr

5-Jun-16 699707.00 Dr

6-Jun-16 699707.00 Dr

7-Jun-16 699707.00 Dr

8-Jun-16 699707.00 Dr

9-Jun-16 475000.00 224707.00 Dr

10-Jun-16 100000.00 124707.00 Dr

## scott hart

I need to look at 4 different column values, saying (in English):

IF J2 = “1” or (IF J2 = “2”, B2 = “46”, and Q2 = “PRCL”), return “PTL/Sortation”, otherwise return “BULK”

this is nested in a very lengthy IF formula, but it is the only piece not working as currently written

## A Thangaraj

=IF(and(E2=”AA”,j2=”7″,”Saturday”,IF(and(E2=”AA”,j2=”1″,”Sunday”,IF(and(E2=”AA”,j26,”LEAVE/WO/HOLIDAY”,(IF(E2$I$1,E2$J$1,”ABSENT”,””))))))

it is not working

## TANGIRALA SRINIVAS

In Excel under the head “LOCATION” there are 3 cities namely ‘X’, ‘Y’ and ‘Z’

The % age of HRA under the head “HOUSE RENT ALLOWANCE” is assigned to the cities are ‘X’=30%, ‘Y’=20% and ‘Z’=10% respectively.

I wish to put a condition in the cell under the head “HOUSE RENT ALLOWANCE” that if the location is ‘X’, it should return the value 30%, If ‘Y’, it should return the value 20% and if ‘Z’ it should return 10%

Please help me to insert appropriate function in the cell, to result the desired value

## Please Leave a Comment!