IF Function in Excel

Quick answer

IF checks whether something is true, then returns one result if it is and another if it isn’t. Reach for it whenever a cell should show or calculate something different depending on a condition, like flagging overtime when someone on your team works more than 38 hours.

=IF(logical_test, value_if_true, [value_if_false])

Works in: Every version of Excel, including Excel 365, Excel 2024, 2021, 2019, 2016 and Excel for the web, on Windows and Mac. Google Sheets has IF with the same syntax.

Syntax

=IF(logical_test, value_if_true, [value_if_false])
ArgumentRequired?What it does
logical_testYesThe question IF asks: anything that works out to TRUE or FALSE, e.g. E2>38. A number works too: 0 counts as FALSE and any other number as TRUE.
value_if_trueYesWhat to return when the test is TRUE: text in double quotes, a number, a cell reference or another formula.
value_if_falseNoWhat to return when the test is FALSE. Default: FALSE if you leave it out completely, or 0 if you type the comma but nothing after it.

How IF works

IF is a fork in the road. Excel asks one yes-or-no question about your data, and the answer decides which way the formula goes. Yes, and you get value_if_true. No, and you get value_if_false.

The test is usually a comparison using =, >, <, >=, <= or <> (not equal to). Text goes in double quotes; numbers and cell references don’t. Text comparisons ignore case, so "casual" matches Casual.

When one question isn’t enough, you can put AND or OR inside the test, nest another IF inside one of the results (Excel allows up to 64), or switch to IFS in Excel 2019 and later.

Examples

All three examples use the Staff sheet from the Bluegum Café workbook, extended to eight staff for one week, with an Employment column added in column F. The data sits in A1:F9 with headers in row 1, and each example’s formula goes in row 2 of its own column (G, H or I) and is filled down to row 9.

Staff IDNameRoleHourly RateHours This WeekEmployment
S01Mia NguyenBarista$28.5032Permanent
S02Jack ThompsonCook$30.1038Permanent
S03Priya SharmaBarista$28.5041Permanent
S04Liam O’BrienKitchen hand$26.2024Casual
S05Chloe MartinFront of house$27.4040Casual
S06Tom WalkerCook$30.1044Permanent
S07Ella DaviesBarista$28.5016Casual
S08Noah KellyManager$34.8045Permanent

Basic: Flag staff who worked overtime

On the Staff sheet, the test reads the hours in E2 and the formula goes in G2, filled down to G9.

=IF(E2>38,"Overtime","Standard")

For Priya Sharma in row 4 (41 hours), the result is Overtime. Jack Thompson in row 3 worked exactly 38 hours, so he gets Standard, because 38 isn’t greater than 38. Use >= if the boundary itself should count.

Real-world: Weekly pay with overtime at time and a half

Still on the Staff sheet, using the rate in D2 and the hours in E2, the formula goes in H2 and fills down to H9. I’ve kept the rule simple here: every hour over 38 is paid at 1.5 times the base rate. Your award will have its own overtime rules, so check those before you run real payroll.

=IF(E2>38,38*D2+(E2-38)*D2*1.5,E2*D2)

For Priya Sharma in row 4, the result is $1,211.25: 38 hours at $28.50 is $1,083.00, plus 3 overtime hours at $42.75 is $128.25. Mia Nguyen in row 2 worked 32 hours, so the test is FALSE and she gets 32 × $28.50 = $912.00.

Advanced: Combine IF with AND to check casual rosters

On the Staff sheet, testing the employment type in F2 and the hours in E2, the formula goes in I2 and fills down to I9. I only want a flag when a casual has gone over 38 hours, so both conditions have to be true.

=IF(AND(F2="Casual",E2>38),"Check roster","OK")

Chloe Martin in row 6 is casual and worked 40 hours, so the result is Check roster. Tom Walker in row 7 worked 44 hours but he’s permanent, so AND returns FALSE and he gets OK. Swap AND for OR and a row gets flagged when either condition is true.

Guru Tip

The IF problem I see most isn’t the formula, it’s the data. Hours pasted in from a payroll export are often stored as text, and Excel treats any text as bigger than any number, so E2>38 comes back TRUE for everyone and the whole team gets flagged for overtime. Check a cell with =ISNUMBER(E2). If it says FALSE, select the column, go to Data > Text to Columns and click Finish to turn it back into numbers. It works the other way too: never put quotes around a number in the test, because E2>"38" is never TRUE.

Common errors

#NAME?: text without quotes

Cause: Text in the formula isn’t wrapped in double quotes, e.g. =IF(E2>38,Overtime,"Standard"), so Excel goes looking for a named range called Overtime. A misspelled function inside the test, like AMD instead of AND, does the same. Fix: Put double quotes around every piece of text: "Overtime".

#VALUE!: the test isn’t TRUE or FALSE

Cause: logical_test points at text Excel can’t read as TRUE or FALSE, e.g. =IF(C2,"Yes","No") where C2 holds Barista. Fix: Turn the test into a comparison: =IF(C2="Barista","Yes","No").

#DIV/0!: an error in the source data

Cause: IF passes along any error in the cells it tests. If E2 already shows #DIV/0! (or #N/A, or any other error), the IF formula returns it too. Fix: Fix the formula that feeds E2. If an error there is expected, wrap the IF in IFERROR to show something friendlier.

Grab the template: IF

Get the Bluegum Café Staff sheet with all three IF examples built in, so you can drop in your own team’s hours and rates.

Frequently Asked Questions

Put AND or OR inside the test. =IF(AND(F2="Casual",E2>38),"Check roster","OK") needs both conditions to be true, while OR needs just one. For more than two possible results, nest another IF or use IFS.

IF tests one condition and returns one of two results. IFS, in Excel 2019 and later and Google Sheets, tests several conditions in order and returns the result for the first one that’s TRUE, so you don’t have to nest IFs.

Use two double quotes with nothing between them: =IF(E2>38,"Overtime",""). The cell looks empty, but it holds empty text, so ISBLANK returns FALSE for it.

Usually a result argument is empty after a comma, like =IF(E2>38,"Overtime",), or it points at an empty cell. Put "" in that argument if you want the cell to look blank instead.

Up to 64. In practice, anything past three or four gets hard to read and check, so switch to IFS or a lookup table with XLOOKUP before it gets that far.

Related functions

IFS

AND

OR

IFERROR