IF Formula in Excel, With Nested IF, IFS, AND and OR

6 min read

The IF formula in Excel returns one value when a test is true and another when it is false: =IF(B2>=C2, “Met”, “Missed”) shows Met when sales in B2 reach the target in C2, and Missed when they do not. For more than two outcomes, put another IF in the false slot (a nested IF), or use IFS, which lists the conditions in order and needs Excel 2019 or later.

That is the whole idea. The rest of this lesson is the part that goes wrong in practice: conditions in the wrong order, numbers written as text, percentages compared against whole numbers, and nested formulas nobody can read a month later.

IF syntax

IF takes three arguments. Only the first is required, but leaving out the third causes problems, as shown further down.

Argument What it means Example
logical_test Anything that is either TRUE or FALSE B2>=C2
value_if_true What to return when the test is TRUE “Met”
value_if_false What to return when the test is FALSE “Missed”

The test almost always uses one of six comparison operators. Text in a test or a result goes in double quotes; numbers and cell references do not.

Operator Meaning Example test TRUE when
= Equal to E2=0 E2 holds 0
<> Not equal to F2<>”Closed” F2 is anything other than Closed
> Greater than B2>500000 B2 is above 5 lakh
< Less than B2 Sales are below target
>= Greater than or equal to B2>=C2 Sales meet or beat target
<= Less than or equal to E2<=2 Two or fewer overdue invoices

The data used throughout

A textile distributor in Ahmedabad pays its five sales reps an incentive based on how they did against their monthly target. The sheet has sales and target in rupees, achievement in column D as =B2/C2 formatted as a percentage, and the number of unpaid invoices each rep’s customers have run up past their due date.

A: Rep B: Sales C: Target D: Achievement E: Overdue invoices
Hetal 540000 500000 108% 1
Jignesh 410000 450000 91.1% 0
Mitesh 735000 600000 122.5% 4
Pooja 300000 450000 66.7% 2
Rakesh 450000 450000 100% 0

A simple IF: two outcomes

The first question is just whether each rep hit target. The formula goes in F2 and is copied down.

Rep =IF(B2>=C2, “Met”, “Missed”)
Hetal Met
Jignesh Missed
Mitesh Met
Pooja Missed
Rakesh Met

Rakesh shows Met because >= includes equality. With > alone, a rep who hit target exactly would be marked Missed, which is the sort of error that gets noticed on payday.

IF can return a calculation as easily as a label. Here, reps who meet target earn 2% of sales and the rest earn nothing.

Rep =IF(B2>=C2, B2*2%, 0)
Hetal 10800
Jignesh 0
Mitesh 14700
Pooja 0
Rakesh 9000

Nested IF: more than two outcomes

The real incentive scheme has slabs. Achievement of 120% or more earns 5% of sales, 100% or more earns 3%, 80% or more earns 1%, and anything below 80% earns nothing. That is four outcomes, so one IF is not enough. Each extra outcome goes inside the previous IF’s false slot.

Part of the formula What it checks
=IF(D2>=120%, 5%, Is achievement at least 120%? If so, 5%
IF(D2>=100%, 3%, If not, is it at least 100%? If so, 3%
IF(D2>=80%, 1%, 0))) If not, is it at least 80%? If so 1%, otherwise 0

Written in one line, that is =IF(D2>=120%, 5%, IF(D2>=100%, 3%, IF(D2>=80%, 1%, 0))). Three IFs, so three closing brackets at the end. The bonus is then sales times the rate.

Rep Achievement Rate from the nested IF Bonus, =B2*F2
Hetal 108% 3% 16200
Jignesh 91.1% 1% 4100
Mitesh 122.5% 5% 36750
Pooja 66.7% 0% 0
Rakesh 100% 3% 13500

Order is everything

Excel stops at the first test that is TRUE. So with “at least” tests, start from the highest slab and work down. Here is the same formula with the slabs in the wrong order, starting from the lowest.

Rep Correct: =IF(D2>=120%, 5%, IF(D2>=100%, 3%, IF(D2>=80%, 1%, 0))) Wrong: =IF(D2>=80%, 1%, IF(D2>=100%, 3%, IF(D2>=120%, 5%, 0)))
Hetal 3% 1%
Jignesh 1% 1%
Mitesh 5% 1%
Pooja 0% 0%
Rakesh 3% 1%

In the wrong version, every rep at 80% or more stops at the first test and gets 1%. The formula raises no error, and Mitesh is paid 7,350 rupees instead of 36,750. The rule: with >= tests, go from highest to lowest; with <= tests, go from lowest to highest.

IFS: the same logic without the nesting

IFS takes pairs of test and result and returns the result for the first test that is TRUE. There is no false slot, so the catch-all goes last as the test TRUE, which is always true.

Formula Result for Hetal Result for Pooja
=IFS(D2>=120%, 5%, D2>=100%, 3%, D2>=80%, 1%, TRUE, 0) 3% 0%
=IFS(D2>=120%, 5%, D2>=100%, 3%, D2>=80%, 1%) 3% #N/A

The second row shows why the TRUE pair matters. Without it, a rep who fits no slab gets #N/A rather than 0.

IFS reads more easily and has no bracket counting, but it needs Excel 2019, Excel 2021 or Microsoft 365. A file that uses it shows #NAME? in Excel 2016. The same order rule applies to IFS as to nested IF. Google Sheets supports both IF and IFS.

IF with AND, OR and NOT

AND and OR let one IF test several conditions at once. AND is TRUE only if every condition is TRUE. OR is TRUE if any one of them is.

The distributor pays the incentive only to reps who met target and whose customers have no more than two overdue invoices. It also wants a call list of reps who either missed target or have three or more overdue invoices.

Rep =IF(AND(B2>=C2, E2<=2), “Eligible”, “Not eligible”) =IF(OR(B2=3), “Call”, “”)
Hetal Eligible blank
Jignesh Not eligible Call
Mitesh Not eligible Call
Pooja Not eligible Call
Rakesh Eligible blank

Mitesh beat target by the widest margin and is still not eligible, because of his four overdue invoices. That is the business rule working as intended, and exactly the case worth testing when you build a formula like this.

NOT reverses a test: =IF(NOT(E2=0), “Has dues”, “Clear”) returns Has dues for Hetal, Mitesh and Pooja. Most people find E2<>0 easier to read, and it does the same thing.

IF on text: exact and partial matches

Text tests in IF are not case-sensitive, so F2=”overdue” matches Overdue. They are exact, though, so “Overdue ” with a trailing space does not match. For a partial match, combine SEARCH, which finds text inside text, with ISNUMBER.

A: Item description =IF(ISNUMBER(SEARCH(“silk”, A2)), “Silk”, “Other”)
Banarasi silk saree Silk
Cotton kurta fabric Other
Silk blend dupatta Silk

SEARCH returns a position number when it finds the text and an error when it does not, so ISNUMBER turns that into TRUE or FALSE.

When to stop nesting and use a table

Nested IF gets unreadable past three or four levels, and Excel allows 64, which is not a target. When the outcomes are slabs, a small lookup table is cleaner: the slabs become data someone can edit without touching a formula.

A: Achievement from B: Rate
0% 0%
80% 1%
100% 3%
120% 5%

With that table in Slabs!A2:B5, an approximate-match lookup returns the right rate for every rep: 3% for Hetal, 1% for Jignesh, 5% for Mitesh, 0% for Pooja and 3% for Rakesh.

Version Formula
Any Excel =VLOOKUP(D2, Slabs!$A$2:$B$5, 2, TRUE)
Microsoft 365 and Excel 2021 onwards =XLOOKUP(D2, Slabs!$A$2:$A$5, Slabs!$B$2:$B$5, , -1)

The dollar signs keep the slab table fixed as the formula is copied down; our guide to absolute and relative cell referencing explains why. Our lesson on VLOOKUP, XLOOKUP and INDEX MATCH, part of this Excel series, covers approximate-match lookups in detail. For exact matches to a fixed list, SWITCH does the same job as a nested IF: =SWITCH(A2, “Hetal”, “West”, “Pooja”, “East”, “Central”).

Mistakes that make IF return the wrong answer

These are the errors that come up most when people check their IF formulas against the expected answer.

Mistake Example What happens Fix
Text without quotes =IF(F2=Met, 1, 0) #NAME? error =IF(F2=”Met”, 1, 0)
Number in quotes =IF(B2>=”450000″, “Met”, “Missed”) Missed for everyone, because Excel ranks any text above any number =IF(B2>=450000, “Met”, “Missed”)
Percentage compared with a whole number =IF(D2>=100, 3%, 0) 0 for everyone, because D2 holds 1.08, not 108 =IF(D2>=100%, 3%, 0) or D2>=1
Slabs in the wrong order Lowest slab tested first Everyone lands in the first slab Test the highest slab first
No value_if_false =IF(B2>=C2, “Met”) FALSE appears for every miss Always give the third argument
Brackets miscounted in a nested IF Missing a closing bracket Excel refuses the formula or suggests a correction One closing bracket per IF at the end

The percentage row is the subtle one. Achievement in column D is stored as a decimal even though it displays as 108%, so a test against 100 is never true. Whenever an IF returns the same answer for every row, check it on a row where you already know what it should say.

Frequently asked questions

What is the IF formula in Excel?

IF returns one value when a condition is true and another when it is false. The syntax is =IF(logical_test, value_if_true, value_if_false), for example =IF(B2>=C2, “Met”, “Missed”). The result can be text, a number, a calculation or another formula.

How do I write a nested IF formula with multiple conditions?

Put the next IF in the value_if_false slot of the one before it, for example =IF(D2>=120%, 5%, IF(D2>=100%, 3%, IF(D2>=80%, 1%, 0))). Excel stops at the first true condition, so with “greater than or equal to” tests, start with the highest threshold. Close one bracket for each IF at the end.

What is the difference between nested IF and IFS?

They give the same result, but IFS lists test and result pairs in a single function instead of putting IFs inside each other, so there is no bracket counting. IFS has no false slot, so end it with TRUE and a default value. IFS needs Excel 2019, Excel 2021 or Microsoft 365, while nested IF works in every version.

How many IF functions can you nest in Excel?

Excel allows up to 64 nested IF functions. In practice anything beyond three or four levels is hard to read and easy to break. For slab-based outcomes, a lookup table with an approximate-match VLOOKUP or XLOOKUP is easier to maintain.

How do I use IF with two conditions in Excel?

Wrap the conditions in AND if both must be true, or OR if either is enough. For example, =IF(AND(B2>=C2, E2<=2), “Eligible”, “Not eligible”) requires sales to meet target and overdue invoices to be two or fewer. AND and OR each accept many conditions, separated by commas.

Why does my IF formula return FALSE?

The test was false and the formula has no value_if_false argument, so Excel shows FALSE by default. Add the third argument, even if it is just “” for a blank cell. If the test is false when you expected true, check for numbers stored as text, trailing spaces in text, and percentages compared against whole numbers.

Build the logic before the formula

The hard part of IF is rarely the syntax. It is writing down the business rule precisely enough, slab boundaries and all, that a formula can follow it, and then testing it on the awkward rows. That is also what an Excel interview task checks. For the other formulas IF usually sits beside, such as SUMIFS and COUNTIFS, see our guide to Excel for data analysis.

SkilloVilla’s Excel: Beginner to Advanced course has a module on conditional functions, alongside operators, lookup, text and date functions, data cleaning, pivot tables and interactive dashboards, taught in live classes by working professionals. If you want Excel inside a full analyst programme with SQL, Python and placement support, see the Data Analytics with Python track.

Power Query in Excel: Get and Transform Data, Step…

Power Query in Excel explained: import with Get Data, clean and reshape in the editor, merge and append, load to a table or the...
SkilloVilla Team
8 min read

How to Build an Excel Dashboard, Step by Step

Build an interactive Excel dashboard step by step: data layout, pivot set-up, KPI formulas with GETPIVOTDATA, chart choices, slicers and refresh.
SkilloVilla Team
8 min read

Data Validation in Excel: Drop-Down Lists and Entry Rules

Data validation in Excel with examples: drop-down lists, dependent drop-downs, date and number limits, custom formula rules and error messages.
SkilloVilla Team
7 min read

Leave a Reply