# Excel IF Formula: Simple to Advanced

**Including: IF with Multiple Criteria, Nested IF, AND, OR functions**

The IF() function has an important place amongst the most popular functions in Excel.

It performs a simple logical test (is a statement TRUE or FALSE?) and, depending on the comparison result, returns one value if a result is a TRUE, or another value if a result is FALSE.

The syntax of the IF() function is the following:

**= IF ( logical_test , [value_if_TRUE] , [value****_if_FALSE] )**

The first two attributes are obligatory, i.e. without them, the formula doesn’t work, and produces an error message.

**logical _test**– a placeholder for the condition we want to test

**value_if_TRUE**– an attribute where we need to specify a value (text, or another function) that the IF formula returns when the result of the logical_test is TRUE

The third parameter is Optional, i.e. we can skip it and in such a case, the IF() function returns the default value FALSE.

**value_if_FALSE**– an attribute for a value, text or another formula that the IF() function must return when the result of the logical test is FALSE.

In other words, IF() function is used to test the specific conditions and can be described as the statement:

**IF** something is true**, ****THEN** return the first value**, ****ELSE** – return then second value.

The simplest IF() function may be written with the first two parameters only.

For example, this formula is absolutely correct:

=IF(C2=1,"Hello!")

This formula tests the condition we set (C2=1) and if it is true, the formula returns the text message (“Hello!”).

Otherwise, it returns the default value FALSE.

**Interesting Fact!!!** You can use another simpler test in Excel for a certain condition. Just place a formula like “=C2>C3” in a cell and press ENTER. If this statement is true, the formula returns the default value – TRUE. Else (i.e. when a value in C2 is NOT larger than a value in C3 cell) the formula will return another default value – FALSE. We use the IF() function in these cases; when we want to trigger some further actions or calculations depending on the results of the logical test.

Typically, the IF() function is used in situations when we need to calculate or flag the results based on certain conditions (for example, smaller than, equal to, greater than and others).

Despite the fact that Excel usually provides multiple choices on how to solve every specific task, the IF() function can play a good role in such cases.

Another simple example of the IF() function:

=IF(C3="Hello!",1, 0)

If a value of the C3 cell is the text “Hello!” then this formula returns the one (1) value.

Else (i.e. if this cell contains any other text, number or blank value), the formula returns zero.

The big advantage of the IF() function (like many other Excel functions) is how we can replace all three arguments in this example with whatever we want/need and it still works properly (if we follow the syntax, of course).

For example, let’s replace the one (as a value_if_true) to another formula “C3+C4” and replace zero value (0) to TODAY() function.

Our initial formula becomes:

=IF(C3="Hello!",C2+C3,TODAY())

That means – IF a value in C2 cell equals one, THEN do the addition C2+C3.

ELSE (i.e. when C2 doesn’t equal “Hello!”), THEN execute the TODAY() function and return its result.

IF() function is a universal function, i.e. it accepts as an attribute different types of a value, such as numeric value, text, date/time, other functions, named ranges and others).

The IF function can be easily used as a part of other more complex formulas.

Moreover, you can use the so-called nested IF() function and replace the **[value_if_false]** with another IF() function.

The most common reason to do that is when you need to create a multi-choice comparison like a waterfall.

The last **value_if_FALSE** attribute is a value that we want the formula to return if the result of ALL logical tests in the formula is FALSE.

We know that we need to use a nested IF() (i.e. one IF() inside another IF() statement) when we have a “but” keyword inside the sentence with a logical test.

Take a look at the screenshot below.

In this example, we need to add the text “flag” if a value is greater than 200, BUT if this value is less than 50 we need to return “follow up” text.

We know that we need to use a nested IF() when there is the “but” keyword in the logical test.

**Pro Tip:** Be cautious. The more IF iterations we use, the more complex the formula becomes and the more difficult it is to understand. In addition, the complex formulas that contain multiple IF functions along with other Excel functions may slow down the calculation speed, especially if they use large ranges of cells. Also, it’s very easy to make an accidental mistake or typo inside the long and complex formulas, and such errors are difficult to trace properly.

The IF() function is often used with other logical functions such as AND() or OR() functions that we will discuss further.

Let’s look at some practical examples…

**TEST CASE №1**

**Adding the word “Good” if the Revenue is greater than 15000**

This is a typical use of the IF() function.

Let’s flag all apps if their Revenue is above 15,000.

**Step 1.** Go to the first cell where we need to insert a formula (cell C5 in this example).

Start the formula with an equal sign (=), add the keyword IF and the opened parentheses to make the formula look like:

=IF(

**Step 2.** The first argument of the IF() function is a logical test.

In this example, we want to flag a value in cell B5 (Revenue) if it is above 15000.

So, let’s continue the formula =IF(B5>15000,

Do not forget to put a comma once this step is ready.

This coma is used by Excel as a delimiter to separate the arguments from each other.

**Pro tip:** We can either type a numeric value in the logical test or use a cell reference to a cell that contains such a value (C2 cell in our example). The second approach is preferred because it gives us more flexibility in the future. Once we copy/paste the formula to the entire range, all we need to do in this case – if want to change that value – is go to the referral cell and change it there without needing to re-write the formula for all related cells.

**NOTE:** Keep in mind that if we want to use this approach, we need to fix the cell reference to look like $C$2. This fixed cell address is required for copying the formula to the entire range. Without that, the formula will return the wrong result. We can simply press F4 to fix the cell reference in the formula (make sure that the cursor is located near the appropriate cell address)

The formula becomes:

=IF(B5>$C$2,

**Step 3.** The second argument of IF() function, as we remember, is a value_if_TRUE.

Let’s type the text “Good” as a second attribute in the formula:

=IF(B5>$C$2, "Good",

Do not forget to put a comma once this step is ready.

Also, be careful – if you type a text value, you need to put it inside a double quotation mark (“*your text*”)

**Pro tip:** We can either type a numeric value in the logical test or use a cell reference to a cell that contains such a value (C3 cell in our example). If in the future we’ll decide to change the “Good” word to something else (“Not Bad”, for example), then all we need to do is go to cell C3 and change that text in the cell without the necessity to re-do the entire formula.

Our formula becomes:

=IF(B5>$C$2,$C$3,

**NOTE:** Don’t forget to fix the cell reference to look like $C$3 address. Press F4 to make an absolute reference. Without that, the formula will return a wrong result.

**Step 4.** The third argument of the IF() function is **value_if_FALSE**. We can skip this attribute (in such cases Excel returns the default value – FALSE). However, if we want to do that in a more aesthetic way, let the formula return a blank value. The blank value in Excel is equal to nothing between two quotation marks, like “”. So, the final version of the formula becomes:

=IF(B5>$C$2,$C$3,"")

**NOTE:** Don’t forget to close the brackets and press ENTER.

**Step 5.** Drag the formula down to the entire range.

Make a quick check manually to ensure that the formula returns the correct result according to our expectations.

TEST CASE №2

**Adding the word “Good” if the Revenue is greater than 15000 and less than 20000**

Let’s flag all apps if their Revenue is above 15,000 but under 20,000

**Step 1.** Go to the first cell where we need to insert a formula (cell D5 in this example).

Start the formula with an equal sign (=), add the keyword IF and the opened parentheses to make the formula look like:

=IF(

**Step 2.** The first argument of the IF() function is a logical test.

In this example, we want to flag a value in cell B5 (Revenue) if it is above 15000 and less than 20,000.

This is a typical situation when we can use the AND() logical function to unite several certain conditions into a single logical test.

AND() function can accept up to 255 conditions as its arguments.

Let’s continue the formula and add the second keyword AND with an opened parenthesis.

Once we’ve done that, we can type both conditions for the logical test inside AND() block and close its second parenthesis.

The formula looks like:

=IF(AND(B5>$D$2,B5<$D$3),

**NOTE:** Don’t forget to fix the cell reference to look like $D$2 and $D$3 address.

Press F4 to make an absolute reference.

Without that, the formula will return a wrong result after we drag it down to the entire range.

**NOTE:** Don’t forget to use a comma once this step is ready.

This comma is used by Excel as a delimiter to separate the arguments from each other.

**Step 2.** The second argument of IF() function, as we remember, is a value_if_TRUE.

Let’s add another cell reference as a second attribute in the formula:

=IF(AND(B5>$D$2,B5<$D$3),$C$3,

**NOTE:** Don’t forget to put a comma after the attribute once this step is ready. Be careful. If you type a text value, you need to put it inside a double quotation mark (“*your text*”)

**Step 3.** The third argument of the IF() function is a value_if_FALSE.

We can skip this attribute and Excel returns the default value – FALSE.

However, the more aesthetic way to do that is to return nothing (or blank value).

Nothing in Excel is denoted as a double quotation mark without any space:

=IF(AND(B5>$D$2,B5<$D$3),$C$3,"")

**NOTE:** Don’t forget to close the bracket and press ENTER.

**Step 4.** Drag the formula down to the entire range.

Make a quick check manually to ensure that the formula returns the correct result according to our expectations.

**TEST CASE №3**

**Adding the word “Good” if the Revenue is greater than 15000 and less than 20000. Adding the word “Exceptional” if the Revenue is greater than or equal to 20,000. Otherwise, keeping the values**

This time we’ll flag all apps as “Good” if their Revenue is above 15,000 and under 20,000.

In addition, we’ll flag them as “Exceptional” if their Revenue is greater than or equal to 20,000

**Step 1.** Go to the first cell where we need to insert a formula (cell E5 in this example).

Start the formula with an equal sign (=), add the keyword IF and the open parentheses to make the formula look like:

=IF(

**Step 2.** The first argument of the IF() function is a logical test.

The first part of the formula in this example is the same as we wrote in the previous example:

=IF(AND(B5>$E$2,B5<$E$3),$C$3,

**NOTE:** Don’t forget to to put a comma after the attribute once this step is ready.

**Step 3.** Usually, the third argument of the IF() function is a value_if_FALSE.

However, this time we need to add the second condition when a value in cell B5 is greater than or equal to 20,000.

We can do that if we use nested IF() function.

Let’s add another IF() block as a third parameter now:

=IF(AND(B5>$E$2,B5<$E$3),$C$3,IF(

**Step 4.** Add the second logical test, and the second value_if_TRUE.

In our example, the formula must return the “Exceptional” keyword if the value in cell B5 is greater than or equal to 20,000.

Let’s type this:

=IF(AND(B5>$E$2,B5<$E$3),$C$3,IF(B5>=$E$3,"Exceptional",

**NOTE:** If you type a value as a text, you need to put it inside a double quotation mark (“*your text*”)

**Step 5.** We need to write a value that the formula will return if the result of both logical tests is FALSE.

In our example, the formula must return the raw Revenue value in this case.

Let’s place this attribute as the third argument in the second IF() block:

=IF(AND(B5>$E$2,B5<$E$3),$C$3,IF(B5>=$E$3,"Exceptional",B5))

**NOTE:** Don’t forget to close the brackets.

We created two IF blocks, so we need to close two brackets at the end.

**Step 6.** Drag the formula down to the entire range.

Make a quick check manually to ensure that the formula returns the correct result according to our expectations.

**TEST CASE №4**

**Adding the word “Flag” if the Revenue is greater than or equal to 20,000 OR it is lesser than or equal to 15,000**

Let’s flag all apps if their Revenue is <= 15,000 or >= 20,000

**Step 1.** Go to the first cell where we need to insert a formula (cell D5 in this example).

Start the formula with an equal sign (=), add the keyword IF and the open parentheses to make the formula look like:

=IF(

**Step 2.** The first argument of the IF() function is a logical test.

In this example we want to flag a value in cell B5 (Revenue) if it is below or equal to 15000 OR above or equal to 20,000.

This is a situation when we can use OR() logical function that allows the testing of multiple logical conditions and return a true value if ANY of them is true.

Let’s continue the formula and add the second keyword OR with an opened bracket.

Once we’ve done that, we can type both conditions for the logical test inside OR() block and close its second parentheses.

The formula looks like:

=IF(OR(B5>=$F$2,B5=<$F$3),

**NOTE: **Press the F4 button on the keyboard to make an absolute reference.

**Step 3.** The second argument of the IF() function, as we remember, is a **value_if_TRUE**.

Let’s add this attribute in the formula:

=IF(AND(B5>$D$2,B5<$D$3),"Flag",

**NOTE:** If you type a text value, you need to put it inside a double quotation mark (“*your text*”)

**Step 4.** The third argument of the IF() function is a value_if_FALSE.

Let’s add a double quotation mark without any space to return a blank value:

=IF(AND(B5>$D$2, B5<$D$3),"Flag","")

**NOTE: **Don’t forget to close the bracket and press ENTER.

**Step 5.** Drag the formula down to the entire range.

Quickly check to ensure that the formula returns the correct result.

**TEST CASE №5**

**Using other formulas inside the logical functions**

Let’s calculate the difference between Actual Revenue and Budget Revenue and flag those cases when the difference is larger than +/- 10%.

**Step 1.** The easiest way to start building such a complex formula is to calculate the core value (this is the +/-10% threshold value in our case).

**Step 2.** Go to the first cell where we need to insert a formula (cell D23 in this example).

Start the formula with an equal sign (=), add the formula to calculate the difference (Actual divided by Budget minus one:

=B23/C23 - 1

**Step 3.** Let’s add the IF() block and the appropriate logical test.

This is a situation when we can use the OR() logical function as we need to flag a value if it is greater than +10% or lower than -10%:

=IF(OR(B23/C23 - 1>10%,B23/C23 - 1<-10%),

**Step 4.** The second argument of the IF() function, as we remember, is a value_if_TRUE.

In this example we need to return the exact deviation, so let’s do that, by simply copying the initial formula.

=IF(OR(B23/C23 - 1>10%,B23/C23 - 1<-10%),B23/C23 - 1,

**Step 5.** The third argument of the IF() function is a value_if_FALSE.

Let’s add a double quotation mark without any space to return a blank value:

=IF(OR(B23/C23 - 1>10%,B23/C23 - 1<-10%),B23/C23 - 1,"")

**NOTE: **Don’t forget to close the bracket and press ENTER.

**Step 6.** Drag the formula down to the entire range.

Quickly check to ensure that the formula returns the correct result.

**TEST CASE №6**

**Using text symbols as the result of the IF() function**

Let’s mark the positive deviation with the up arrow and the negative deviation with the down arrow.

**Step 1.** We’ll continue the previous example.

Let’s say we want to mark all positive deviations with a symbol that looks like an up arrow and all negative deviations with a symbol that looks like a down arrow.

First of all, a few preparations.

Let’s go to the cells above the test range (A20 and A21 cells in this example).

Feel free to select any other cells if you prefer.

**Step 2.** Insert the symbols that will indicate all positive and negative deviations.

To do this, we need to go on the INSERT tab on the Excel Ribbon and follow the path: *INSERT > Symbol > Arial > Geometric Shapes*

Click **Insert** once you have selected a shape.

Go to another cell below and insert the second arrow in the same way.

**Step 3.** Go to the first cell in the range where we want to add these visual indicators.

Replicate the IF() function with the cell references containing the arrows as the value_if_TRUE and value_if_FALSE attributes.

=IF(B23/C23 - 1>10%,$A$20,IF(B23/C23 - 1<-10%,$A$21,""))

**NOTE:** Don’t forget to close the bracket and press ENTER.

**Step 4.** Drag the formula down to the entire range.

Quickly check that the formula returns the correct result.

## Workbook for Download

Feel free to Download the Workbook HERE.

**Excel Dashboards that Inform & Impress**

saifApril 26, 2018 at 8:03 pmthanks a lot dear Leila

Leila GharaniApril 26, 2018 at 8:22 pmYou’re very welcome Saif.

nasir garba suleMay 16, 2018 at 2:52 pmthank you for ythe sharing

Leila GharaniMay 23, 2018 at 5:40 pmYou’re very welcome Nasir.

SamuelAugust 8, 2018 at 1:23 pmThank you

Leila GharaniAugust 18, 2018 at 6:34 pmYou’re very welcome Samuel.

Sandeip ShuklaAugust 23, 2018 at 6:11 pmHello ma’am your tutorials videos and the way you present your whole content is amazing. I want to be like you, an excel expert what should I do? your teaching skills are great.

Leila GharaniAugust 23, 2018 at 7:00 pmThank you Sandeip. I’m glad you like the tutorials. I started by answering other people’s Excel questions, reading books, taking courses, using what I learnt at work and then making videos….

AsadSeptember 14, 2018 at 6:47 amThanks for your contribution.

KERİSeptember 15, 2018 at 3:09 pmWHERE İS WORKBOO FRO DOWLOADİNG

Leila GharaniSeptember 20, 2018 at 3:33 pmHi – it’s at the bottom of the post – you’ll see a workbook icon there.

gigsSeptember 16, 2018 at 1:42 amNSC Last 3 Months Without 13th Month Persistency

50,000 -99,999 12%

100,000 – 199,999 14%

200,000 – 299,999 18%

300,000 – 499,999 23%

500,000 and up 30%

Good day. above is the sample range. would like to ask help on how to to put it in a cell that the result will be either of the percentage if any of the ranges will appear?

thanks

roderick

KhadarOctober 11, 2018 at 12:55 pmHello Leila,

Excellent teaching skills…

Leila GharaniOctober 11, 2018 at 2:14 pmThank you! I’m glad you find the tutorial easy to follow.

AnjumOctober 14, 2018 at 6:06 pmThank you! Amazing and well-explained videos. Really useful indeed.

Ershadul HoqueOctober 31, 2018 at 8:55 amIs there any option/formula to find out the lowest or highest value from 3 number/column?

Leila GharaniNovember 7, 2018 at 5:46 pmYou can use the MAX function here. Type in =Max(highlight the range of numbers)

MasoodDecember 19, 2018 at 7:44 pmvery well explained. I just got stuck into a calculation on excel. searched the youtube and found it. great job Leila.

Leila GharaniDecember 20, 2018 at 9:09 amThank you!

manyuckisJanuary 18, 2019 at 1:41 pmHi, are there any more workbooks to practice on? thanks on the tutorial by the way. it helps a lot.

Leila GharaniJanuary 18, 2019 at 1:59 pmI’m glad you like the tutorial. I’m not sure if you’re registered for my advanced Excel course but there is an exercise workbook there for all the functions we learn (answers included on separate tabs).

SuzanaJanuary 27, 2019 at 6:35 pmThank you Leila!

Leila GharaniJanuary 28, 2019 at 12:03 pmYou’re very welcome Suzana :)

RajaFebruary 2, 2019 at 7:13 pmThank you leila for your excellent tutorial like excel dashboard.I would like to learn exclusive advanced excel dashboard from you with all advanced functions and tools used.Could you please send me all details in my email with affordable price so that i could able to pay the amount.

Leila GharaniFebruary 9, 2019 at 6:08 pmHi Raja – you can find all the information on the course here. Thank you for your support.

John Maina GatonyeFebruary 5, 2019 at 10:50 amVery Well presented.

AlfredMarch 14, 2019 at 4:51 amNever learnt so much in such a short time. Thanks Leila for keeping your tutorials so simple and easy to understand. Your Index/Match video was very helpful. How do i subscribe for the advanced course?

Bryon SmedleyApril 7, 2019 at 2:07 pmBelow is the link for the “Advanced Excel: Top 10 Excel Tips and Formulas” course.

https://courses.xelplus.com/p/advanced-excel-work-smarter-top-10-excel-tips-formulas

Although this course was created using Excel 2010, the information is still as relevant in the most recent version(s) of Excel.

Thank you for your interest.

VadivelanMarch 21, 2019 at 11:57 amHi Leila,

I have issue on excel formula, can please solve the issue.

I have done stock count in excel for count 1 and count 2, the formula i set is working but i set for count 3 is not working. below is the detail.

A B C

BOOKED QTY COUNT 1 COUNT 2 FINAL QTY

30 29 30 30 The formula is =IF(C1=0,B1,C1) is working but

If i used same formula for count 3 is not working.

A B C D

BOOKED QTY COUNT 1 COUNT 2 Count 3 FINAL QTY

30 28 29 30 30 The formula is =IF(D1=0,B1,C1,D1)

Please solve this issue, Thanks

Bryon SmedleyApril 7, 2019 at 7:48 pmThank you for your question. To aid in answering your question, the following link to the Microsoft Excel Tech Community would be the best place to pose your question. If you have a sample file to upload, this would greatly aid in developing a course of action.

The Excel Tech Community has some of the finest minds in the industry. No matter your issue, I’m certain someone there can inform you of the best way to reach your solution.

Microsoft Excel Tech Community

With over 25K members and almost 30K posts, your solution is either ready and waiting or has the possibility of being answered more quickly than we may be able.

Thank you for taking the time to write. I hope you find success with this fantastic group of Excel enthusiasts.

XelPlus Team

TamerMay 3, 2019 at 6:09 amVery good

I learned a lot from you thanks for advanced excel

Waiting for next one

Jörg WeberMay 11, 2019 at 2:31 pmThanks a lot also from me.

For me it is a little bit harder to leran because I have only School english. But I can understand you very well and so I learn very good.

Thanks a lot

kishoreJune 14, 2019 at 12:13 pmThank you Leila!

Leila GharaniJune 19, 2019 at 2:38 pmYou’re very welcome Kishore :)