In Part 1 of our Excel IF function tutorial, we started to learn the nuts and bolts of the Excel IF function. As you remember, we discussed a few IF formulas for numbers, dates and text values as well as how to write an IF statement for blank and non-blank cells.

However, for powerful data analysis, you may often need to evaluate multiple conditions at a time, meaning you have to construct more sophisticated logical tests using multiple IF functions in one formula. The formula examples that follow below will show you how to do this correctly. You will also learn how to use Excel IF in array formulas and learn the basics of the IFEFFOR and IFNA functions.

In summary, there can be 2 basic types of multiple conditions - with AND and OR logic. Consequently, your IF function should embed an AND or OR function in the logical test, respectively.

- AND function. If your logical test contains the AND function, Microsoft Excel returns TRUE if
**all the conditions**are met; otherwise it returns FALSE. - OR function. In case you use the OR function in the logical test, Excel returns TRUE if
**any of the conditions**is met; FALSE otherwise.

To better illustrate the point, let's have a look at a few IF examples with multiple conditions.

Suppose, you have a table with the results of two exam scores. The first score, stored in column C, must be equal to or greater than 20. The second score, listed in column D, must be equal to or exceed 30. Only when both of the above conditions are met, a student passes the final exam.

The easiest way to make a proper formula is to write down the condition first, and then incorporate it in the logical_test argument of your IF function:

Condition: AND(B2>=20, C2>=30)

IF/AND formula: `=IF((AND(C2>=20, D2>=30)), "Pass", "Fail")`

Easy, isn't it? The formula tells Excel to return "Pass" if a value in column C >=20 AND a value in column D >=30. Otherwise, the formula returns "Fail". The screenshot below proves that our Excel IF /AND function is correct:

In practice, a seemingly correct IF / AND formula may result in an error because of this specificity. For example, the formula `=IF(AND(A2<>0,(1/A2)>0.5),"Good", "Bad")`

will return "Divide by Zero Error" (#DIV/0!) if cell A2 is equal to 0. The avoid this, you should use a nested IF function:

`=IF(A2<>0, IF((1/A2)>0.5, "Good", "Bad"), "Bad")`

You use the combination of IF & OR functions in a similar way. The difference from the IF / AND formula discussed above is that Excel returns TRUE if **at least one** of the specified conditions is met.

So, if we modify the above formula in the following way:

`=IF((OR(C2>=20, D2>=30)), "Pass", "Fail")`

Column E will have the "Pass" mark if either the first score is equal to or greater than 20 **OR** the second score is equal to or greater than 30.

As you see in the screenshot below, our students have a better chance to pass the final exam with such conditions (Scott being particularly unlucky failing by just 1 point : )

More formula examples can be found in Excel IF OR functon.

In case you have to evaluate your data based on several sets of multiple conditions, you will have to employ both AND & OR functions at a time.

In the above table, suppose you have the following criteria to evaluate the students' success:

- Condition 1: column C>=20 and column D>=25
- Condition 2: column C>=15 and column D>=20

If either of the above conditions is met, the final exam is deemed passed, otherwise - failed.

The formula might seem tricky, but in a moment, you will see that it is not! You just have to express two conditions as AND statements and enclose them in the OR function since you do not require both conditions to be met, either will suffice:

`OR(AND(C2>=20, D2>=25), AND(C2>=15, D2>=20)`

Finally, use the above OR function as the logical test in the IF function and supply value_if_true and value_if_false arguments. As the result, you will get the following IF formula with multiple AND / OR conditions:

`=IF(OR(AND(C2>=20, D2>=25), AND(C2>=15, D2>=20)), "Pass", "Fail")`

The screenshot below indicates that we've got the formula right:

Naturally, you are not limited to using only two AND/OR functions in your Excel IF formulas. You can use as many logical functions as your business logic requires, provided that:

- In Excel 2016, 2013, 2010 and 2007, your formula includes no more than 255 arguments, and the total length of the formula does not exceed 8,192 characters.
- In Excel 2003 and lower, you can use up to 30 arguments and the total length of your formula shall not exceed 1,024 characters.

If you need to create more elaborate logical tests for your data, you can include additional IF statements in the value_if_true and value_if_false arguments of your Excel IF formulas. These multiple IF functions are called **nested IF functions** and they may prove particularly useful if you want your formula to return 3 or more different results.

Here's a typical example: suppose you want not simply to qualify the students' results as Pass/Fail, but define the total score as "*Good*", "*Satisfactory*" and "*Poor*". For instance:

- Good: 60 or more (>=60)
- Satisfactory: between 40 and 60 (>40 and <60)
- Poor: 40 or less (<=40)

To begin with, you can add an additional column (E) with the following formula that sums numbers in columns C and D: `=C2+D2`

And now, let's write a nested IF function based on the above conditions. It's considered a good practice to start with the most important condition and make your functions as simple as possible. Our Excel nested IF formula is as follows:

`=IF(E2>=60, "Good", IF(E2>40, "Satisfactory", "Poor "))`

As you see, just one nested IF function is sufficient in this case. Naturally, you can nest more IF functions if you want to. For example:

`=IF(E2>=70, "Excellent", IF(E2>=60, "Good", IF(E2>40, "Satisfactory", "Poor ")))`

The above formula adds one more conditions - the total score of 70 points and more is qualified as "Excellent".

For more information about Excel IF with multiple conditions, please see How to use nested IF in Excel.

Like other Excel functions, IF can be used in array formulas. You may need such a formula if you want to evaluate every element of the array when the IF statement is carried out.

For example, the following array SUM/IF formula demonstrates how you can sum cells in the specified range based on a certain condition rather than add up the actual values:

`=SUM(IF(B1:B5<=1,1,2))`

The formula assigns a certain number of "points" to each value in column B - if a value is equal to or less than 1, it equates to 1 point; and 2 points are assigned to each value greater than 1. And then, the SUM function adds up the resulting 1's and 2's, as shown in the screenshot below.

Earlier in this tutorial, we've discussed a few IF formula examples demonstrating how to use the Excel IF function with logical functions AND and OR. Now, let's see what other Excel functions can be used with IF and what benefits this gives to you.

When discussing nested IF functions, we wrote the formula that returns different ranking (Excellent, Good, Satisfactory or Poor) based on the total score of each student. As you remember, we added a new column with the formula that calculates the total of scores in columns C and D.

But what if your table has a predefined structure that does not allow any modifications? In this case, instead of adding a helper column, you could add values directly in your If formula, like this:

`=IF((C2+D2)>=60, "Good", IF((C2+D2)=>40, "Satisfactory", "Poor "))`

Okay, but what if your table contains a lot of individual scores, say 5 different columns or more? Summing so many figures directly in the IF formula would make it enormously big. An alternative is embedding the SUM function in the IF's logical test, like this:

`=IF(SUM(C2:F2)>=120, "Good", IF(SUM(C2:F2)>=90, "Satisfactory", "Poor "))`

In a similar fashion, you can use other Excel functions in the logical test of your IF formulas:

**IF and AVERAGE:**

`=IF(AVERAGE(C2:F2)>=30,"Good",IF(AVERAGE(C2:F2)>=25,"Satisfactory","Poor "))`

The formulas retunes "Good" if the average score in columns C:F is equal to or greater than 30, "Satisfactory" if the average score is between 29 and 25 inclusive, and "Poor" if less than 25.

**IF and MAX/MIN:**

To find the highest and lowest scores, you can use the MAX and MIN functions, respectively. Assuming that column F is the total score column, the below formulas work a treat:

MAX: `=IF(F2=MAX($F$2:$F$10), "Best result", "")`

MIN: `=IF(F2=MIN($F$2:$F$10), "Worst result", "")`

If you'd rather have both the Min and Max results in the same column, you can nest one of the above functions in the other, for example:

`=IF(F2=MAX($F$2:$F$10) ,"Best result", IF(F2=MIN($F$2:$F$10), "Worst result", ""))`

In a similar manner, you can use the IF function with your custom worksheet functions. For example, you can use it with the GetCellColor / GetCellFontColor functions to return different results based on a cell color.

In addition, Excel provides a number of special IF functions to analyze and calculate data based on different conditions.

For example, to count the occurrences of a text or numeric value based on a single or multiple conditions, you can use COUNTIF and COUNTIFS, respectively. To find out a sum of values based on the specified condition(s), use the SUMIF or SUMIFS functions. To calculate the average according to certain criteria, use AVERAGEIF or AVERAGEIFS.

For the detailed step-by-step formula examples, check out the following tutorials:

- How to use the COUNTIF in Excel
- Using Excel COUNTIFS and COUNTIF with multiple conditions
- SUMIF in Excel - formula examples to conditionally sum cells
- How to use Excel SUMIFS and SUMIF with multiple criteria

You already know a way to spot blank and non-blank cells using the ISBLANK function. Microsoft Excel provides analogous functions to identify text and numeric values - ISTEXT and ISNUMBER, respectively.

Here's is example of the nested Excel IF function that returns "Text" if cell B1 contains any text value, "Number" if B1 contains a numeric value, and "Blank" if B1 is empty.

`=IF(ISTEXT(B1), "Text", IF(ISNUMBER(B1), "Number", IF(ISBLANK(B1), "Blank", "")))`

Sometimes, you can achieve the desired result by embedding the IF statement in some other Excel function, rather than using another function in a logical test.

Here's another way how you can use the CONCATINATE and IF functions together:

`=CONCATENATE("You performed ", IF(C1>5,"fantastic!", "well"))`

I believe you hardly need any explanation of what the formula does, especially looking at the screenshot below:

Both of the functions, IFERROR and IFNA, are used to trap errors in Excel formulas and replace them with another calculation, predefined value or text message. In earlier Excel versions, you can use the IF ISERROR and IF ISNA combinations instead.

The difference is that IFERROR and ISERROR handle all possible Excel errors, including #VALUE!, #N/A, #NAME?, #REF!, #NUM!, #DIV/0!, and #NULL!. While IFNA and ISNA specialize solely in #N/A errors.

Here is the simplest example of the IFERROR formula:

`=IFERROR(B2/C2, "Sorry, an error has occurred")`

As you see in the screenshot above, column D displays the quotient of the division of a value in column B by a value in column C. You can also see two error messages in cells D2 and D5 because everyone knows that you cannot divide a number by zero.

In some cases, however, you may not want to trap all errors, but rather test the condition causing a specific error. For example, to replace a divide by zero error with your own message, use the following IF formula:

`=IF(C2=0, "Sorry, an error has occurred", B2/C2)`

And that's all I have to say about using the IF function in Excel. I thank you for reading and hope to see you on our blog next week!

Excel formulas
CSV
Excel functions
Print
Vlookup in Excel
Merge data in Excel
SumIf
Excel CountIf
Excel Compare
Excel If statement
Excel Charts
Pivot Table
Updates
Excel conditional formatting
Excel formatting
Excel time
Excel duplicates
Excel date
Excel tips
Excel macro
Outlook
Google Sheets
Outlook duplicates
Outlook templates

-->
## 2,107 Responses to "Excel IF statement with multiple AND/OR conditions, nested IF formulas, and more"

I have an IF formula =IF(D8="X","1","") and now I want to add up the lines that have a 1 in them .. what type of formula will I need?

Hi Brad did you get any solution for that? I am also looking for the same.

Try =COUNTIF([Your Desired Range],"1")

Hi Svetlana..

In Excel Solver, my variable cell output should be either 0 or 20.

how to add this constraint please.

hi , i m trying to formula for this statment

if A1 greater then 20 twenty then add next row number..

A1 B2

25

32

20

5

I WANT IN B2 NOT MORE THEN 20. ADD NEXT ROW ABOVE 20

hi , i m trying to formula for this statment

if A1 greater then 20 twenty then add next row number..

A1 B2

25

32

20

5

I WANT IN B2 NOT MORE THEN 20. ADD NEXT ROW ABOVE 20

Hello,

I want to calculate an expiry date of a product. The products either have a 5year or 10year working life depending on whether its construction is "rubber" or "synthetic". Over three columns I have MATERIAL, DATED FITTED, EXPIRY DATE. If the material is rubber then I enter =DATE(YEAR(K6)+5,MONTH(K6),DAY(K6)) in the EXPIRY DATE. If the material is synthetic I enter =DATE(YEAR(K6)+10,MONTH(K6),DAY(K6)). Is there a way to make the EXPIRY DATE Column decide automatically how many years to add depending on the contents of the MATERIAL column?

I'm Really struggling with this.

Many thanks.

Tom

I want multiple of this formula =IF(SUM(COUNTIF(A3,{"*ANCHORAGE*"})),"Alaska",IF(SUM(COUNTIF(A3,{"*Atlanta*"})),"Georgia"))

for several cities, but excel does not let me do more than two IF statements, is there another way to do multiple if statements in one formula?

You can nest as many IF statements as you'd like in Excel.

Just follow the formula:

=IF(Condition,True,IF(Condition,True,IF(...,False)...)

You're just replacing the False part of the IF statement with another IF statement every time. If the first condition isn't true, then it checks for the second, and then the third, etc.

please help in the below issue

i have count of 100 people name, and i have to add column B each person against 1 to 10 number.

So it will be like this

Mango 1

Mango 2

Mango 3

Mango 4............

please let me know the formula

its Cntr D i have used but i have large number of data so i can not use the same.

please suggest its urgent

Hi - I am trying to work out how to write a formula for the following:

If cellvalue1, "No"

If cellvalue is blank, ""

I have got the yes and no working by using this formula: =IF(E7>1,"No","Yes") but at the moment if there was nothing in cell E7, the cell I have the formula in shows "Yes" and I really want it to be blank (i.e. only say yes or no where there is an actual value in E7). Hope someone can help!

Thanks

kirstie

Can you please help me to solve this

Fail+Pass+Pass = PASS

Pass+Fail+Pass = PASS

Pass+Pass+Fail = FAIL

Fail+Pass+Pass = FAIL

HOW ??????

Hi

Please help me..

My cell values are as follows:-

A1 B1 C1 D1

62 31 0

In cell D1 I need to use a formula that will calculate the value in A1 if C1 =0, but if

C1 >0, then I need to SUM B1+C1

hi.

try this

=IF(C10,C1+B1,0)

We want customers to receive a coupon based on the department they purchased from.

Coupon amounts by department:

Electronics—$25 coupon.

Toys—$20 coupon.

Sports—$15 coupon.

Shoes—$10 coupon.

Every other department—$5 coupon.

Create a column named “Coupon.”

Create a formula that displays the coupon amount for each customer based on department

Calculate the following score sheet

NAME GA TWI EWE FRAFRA PERCENT REMARK

a. Use data validate to allow NAME to have not more than 8 characters.

b. When a cell in the name section is selected, the user should be prompted not to type more

than 8 characters in the Name column.

c. Apply conditional formatting to display marks in red color and one decimal place if it is

smaller than 50.

d. Populate your table with the following data:

e. Calculate PERCENT (Note: Percent is the average score for a student) and REMARK.

REMARK is awarded as below:

i. EXCELLENT if any of the marks obtained is more than 90.

ii. V. GOOD if percent is greater than 60

iii. GOOD if percent is greater than 50

iv. FAIL if percent is below 50 or any of the mark is below 60

NAME GA TWI EWE FRAFRA PERCENT REMARK

SATOKA 40 59 24 100

ME LEE 60 67 80 100

EFO LEE 98 1 72 90

LEE SON 88 99 84 60

YOU LEE 76 100 100 90

Please , can someone help me with an appropriate function for question e

Cell A2-A10 has serial numbers

Cell B2-B10 has YES or NO

i want a formula for C2,

IF cell B2 is yes then i need the cell A2's value in cell C2

IF cell B3 is no then i need the cell C3 to be empty

I need to set formula for the target with criteria as check region is tier I or II then ach.vs target % check , ach.vs ach %, industry growth %, cagr% and stretch the % with 5 or 10 below matrix;

Ach Vs Target Fy 2020 E Ach Vs Ach Fy 2020 E Market share Fy 2020 E YoY Growth Fy 2020 E CAGR Target Growth over PY ach

Tier I Tier II Tier I Tier II Tier I Tier II Tier I Tier II Tier I Tier II Tier I Tier II

65% 65% 0% 0% 2% 2% -15% -15% -10% -10% 5% 5%

80% 80% 10% 10% 8% 8% 1% 1% 1% 1% 10% 10%

90% 90% 30% 30% 10% 10% 5% 5% 5% 5% 15% 15%

100% 100% 50% 50% 15% 15% 10% 10% 10% 10% 20% 25%

125% 125% 90% 90% 18% 18% 20% 20% 20% 20% 25% 30%

Hi Jessica, I am trying to use IF function e.g. If M3:M519 = JNB, then to add an amount that is in the corresponding column cell e.g if M58 = JNB then to add the amount in the corresponding cell e.g. B58 = 195

Does that make sense?

regards Tracy

Hi,

I have some data in which both column and row contains lot of data.

Just want to know that :

1.Column contains data in yellow colour.

2.Want to sum each row with yellow colour .

3.Total of yellow colour data pertains to different different user name.

4.Hence result should be total of yellow colour data in front of respective user name.

Kindly help on this.

Please give me a functio for a cell, as follows:

in cell b3 with only two value conditions b3=1 or b3=3

in order that:

than if b3=1 to give in cell c3 value effect 5

if b3=3 to give in cell c3 value effect 10

thank you.

Please give me a functio for a cell, as follows:

in cell b3 with only two value conditions b3=1 or b3=3

in order that:

if b3=1 to give in cell c3 the value effect 5

if b3=3 to give in cell c3 the value effect 10

thank you.

Please will you give me the function IF in a cell C3 depending of a value in cell B3 with two values , as follows:

in cell b3 with only two values conditions TRUE, with B3=1 or B3=3, in order that:

-for the TRUE two conditions: if B3=1 to give in cell C3 the value effect 5 , and

if B3=3 to give in cell C3 the value effect 10

-for the FALSE condition, if B3 has different value of 1 or 3, to give in cell C3 the value effect 0 (zero).

Thank you.

Hello Dim!

If I understand your task correctly, the following formula should work for you:

=IF(B3=1,5,IF(B3=3,10,0))

If there is anything else I can help you with, please let me know.

Hi,

if it is in excel workbook in one sheet >95 and in other sheet <95 written there, so how we can take average of that( with sign).

please help me to resolve this issue.

Regards,

Vivek

Hello!

If I understand your task correctly, the following formula should work for you:

=IF(OR (AND(Sheet1!A1<95,Sheet2!A1>95), AND(Sheet1!A1>95,Sheet2!A1<95)), AVERAGE(Sheet1!A1,Sheet2!A1),0)

I hope it’ll be helpful.

I'm trying to embed a MID statement for the answer if true. My forumula isn't working, however: =IF(B2=55,(mid(A2,4,2),B2).

Any ideas?

Hello, Annie!

Please try the following formula:

=IF(B2=55,MID(A2,4,2),B2)

How to calculate through xl formula dragging for 2000 rows

Logic.1 Sum first numeric cell starting from A2 at E i.e for row 1 is A2, row2 B2, row 3 C3 and row 4 B4

Logic.2 Sum from 2nd numeric cell to end

i.e for row 1 B1:D1 for row2 B2:D2 for Row3 C3:D3 and row4 B4:D4

- A B C D E F

1 1000 2000 3000 4000

2 - 500 600 700

3 - - 5000 6000

4 - 9000 7000 8000

Hi quick question

How can i do the following

Put conditional pricing based on the criteria..

If H2 is in special customer list (E2:E) than rate = D2 if not a special customer than rate is as listed in Pricing list according to gallon amount in cell J2

Thanks

https://docs.google.com/spreadsheets/d/1uk8MCtQ3ZdYR_KfJVWY4Svnx-Rmg11YuSePHxefn0jM/edit?usp=sharing

I have a problem where I want to generate a dynamic list based on 2 variables (an odd and a dollar amount) e.g.

Variable 1 - 1.2

Variable 2 - $1.00

I have the following function:

=IF(countif($E$1:E1,"No")=0,(if(($A$1*C1)>($A$2*4), ($A$1*C1)-($A$2*2), if(($A$1*C1)>($A$2*8), ($A$1*C1)-($A$2*4), if(($A$1*C1)>($A$2*16), ($A$1*C1)-($A$2*8),(if(countif($E$1:E1,"No")=1,(if(($A$1*C1)>($A$2*8), ($A$1*C1)-($A$2*4), if(($A$1*C1)>($A$2*16), ($A$1*C1)-($A$2*8)))),($A$1*C1))))))))

Cell C1 is the value of Variable 1 * Variable 2. Column E, is if a condition has been met, and an amount has been deducted from the outcome in the list.

Example of the list:

1 $1.20 $0.20 Yes

2 $1.44 $0.24 Yes

3 $1.73 $0.29 Yes

4 $2.07 $0.35 Yes

5 $2.49 $0.41 Yes

6 $2.99 $0.50 Yes

7 $3.58 $0.60 Yes

8 $2.30 -$1.28 No

9 FALSE -$2.30 No

I want #9 to be $2.30 * Variable 1, until it hits (Variable 2 * 8). Once it hits that limit, it will then be reduced by Variable 2 * 4.

There are quite a few more "limits" that I would like to set, but I've reduced them to simplify. Any help or suggestions would be great.

Thanks.

Hi..pls help me for the below conditions.

condition 1: wen entering D4 value =A, then E4 value should be=A

condition 2: wen entering D4 value =blank, then E4 value should be =blank

condition 3: if D4A and D4blank, means it has some data. so that time E4 should be "B".

Give me formula for above condition.

Thanks..

Hi Praveen,

If I understand your task correctly, the following formula should work for you:

=IF(D4="A", "A", IF(D4="", "","B"))

How to write the formula of if cell contains the range ±0.25 then return YES otherwise return NO in the Excel.

Hi Samy,

Assuming you are comparing cell B1 against A1, the following formula will return "yes" if B1 equals A1±0.25, otherwise "no":

=IF(AND(B1>=A1-0.25, B1<=A1+0.25), "yes", "no")

Dear.

In a range i have 10 customer name under this name i want to count the customer repeated ie duplicate as 1 and only one condition if cash customer more than one count it all ie 3 cash customer and 7 other customer total is 10 customers please help me to create one formula

Regards

Noby Paul

Dear.

In a range i have 10 customer name under this name i want to count the customer repeated ie duplicate as 1 and only one condition if cash customer more than one count it all ie 3 cash customer and 7 other customer total is 10 customers please help me to create one formula

Regards

Noby Paul

Thanks for your providing this is good lesson for me.

I have two products in kilograms with different Rates and if I sell my products more than first sell . I want continually minus .like

Qty Rate Amount Qty Rate Amount Sell qty sell rate Sell amount

12*15=180,. 10*17=170. Formula cell 15*....=....

what formula should I write here?

90-94, with honors

95-97, with high honors

98-100, with highest honors

Please help.

Hello!

Please use the following formula

=IF(A1 >= 90,IF(A1 <= 94,"Honor",IF(A1 <= 97, "High Honor", "Highest Honor")),"")

I hope this will help, otherwise please do not hesitate to contact me anytime.

Hi Svetlana

I want to add two cells (G15+G9) and then use the result in another formula. However if one of the cells is empty I get a #value result. How can I get the result of either one of the cells is empty.

Hello Hino!

If cells G15 and G9 contains numbers, it is not quite clear why you get an error. I can suppose that there is a number in one of the cells and the other one contains a space or another non-printing character. Anyway, I recommend using the IFERROR function to process errors in formulas. You can find more info about this function here: https://www.ablebits.com/office-addins-blog/2017/09/27/excel-iferror-function-with-formula-examples/

Alternatively, you may find our Remove Characters tool useful for searching and deleting spaces and other invisible symbols. The tool is available as a part of our Ultimate Suite for Excel. Feel free to install the add-in in a trial mode and test the tools for 30 days for free: https://www.ablebits.com/files/get.php?addin=xl-suite&f=free-trial

I hope it’ll be helpful.

Hi. Please help

I have 23,000 in income. I need to pay 0% in the first 2,000.

3% up to 5,000.

4% from 5,ooo to 10,000

5% on anything above 10,000

I need all the calculation in one formula.

I used to make a formulae using the following scenarios;

> 1,000 amount would appear in the column to all who are non regular status

> 500 for non regular

example: If employee is on a non regular status the equal amount due for employee we will are 500.

hello