In Google Sheets, an IF statement uses the IF function to test a condition and return one result when it is true and another when it is false. For example, with a score in A2, =IF(A2>=60,"Pass","Fail") displays Pass for a score of 60 or higher and Fail otherwise.
What an IF statement does
An IF statement lets a spreadsheet make a choice from the values in its cells. It checks a logical condition, such as whether a number exceeds a threshold or whether a cell matches a word, then returns the result that corresponds to the condition. The result can be text, a number, a date, a calculation, or another formula.
Google Sheets calls this function IF. Its general structure is =IF(condition, value_if_true, value_if_false). The condition must be something Sheets can evaluate as true or false. The final two arguments tell it what to return for each outcome. The false result is optional; if you leave it out, Sheets returns FALSE when the condition is not met.
IF is useful for labeling records, applying simple rules, and making a calculation depend on a test. For instance, a sales sheet could label an order as eligible for a discount, while a classroom grade sheet could classify scores as passing or failing. It does not change the source data: it returns a result in the cell containing the formula.
Write a basic IF formula
Start with a clear test and decide what should happen on both sides of it. Suppose A2 contains the number 74 and the passing mark is 60. Enter this formula in another cell:
With a score of 74 in A2, the formula is =IF(A2>=60,"Pass","Fail"). It returns Pass because 74 is greater than or equal to 60. If A2 contained 55, it would return Fail.
The comparison symbol is part of the condition. Common options include = for equal to, <> for not equal to, > for greater than, < for less than, and the combined forms >= and <=. Text values need quotation marks inside the formula, while cell references and numeric values do not.
For a price example, suppose B2 contains 12 units and C2 contains a unit price of 8. If orders of 10 or more units receive a 10% discount, enter this in D2:
With quantity 12 in B2 and unit price 8 in C2, use =IF(B2>=10,B2*C2,B2*C2*0.9). The condition is true, so the result is 96, not 86.4: the formula as written returns the full price. To apply a 10% discount to qualifying orders, reverse the two calculations as follows: =IF(B2>=10,B2*C2*0.9,B2*C2). That returns 86.4 for this example. This illustrates why it is worth checking which calculation sits in the true and false positions.
Compare values and text
Conditions can compare a cell with a fixed value or with another cell. For example, a due-date tracker might compare a date in B2 with the current date using TODAY(), while an inventory sheet might compare the stock count in A2 with a reorder point in B2. Dates in Google Sheets are stored as numbers, so comparisons work when the cells contain valid date values rather than date-like text.
For text matching, capitalization is generally not significant in a direct equality comparison. If A2 contains Paid, this formula returns Complete:
With the status Paid in A2, enter =IF(A2="Paid","Complete","Check status"). The result is Complete. If the cell contains a different status, the formula returns Check status. Leading or trailing spaces can still cause an apparent mismatch, so a value such as Paid followed by a space may not behave as expected.
A formula can also return a calculation rather than a label. In the discount example, the true and false outcomes are arithmetic expressions. This is often more useful than writing separate formulas for different cases, but it makes the outcomes worth reviewing carefully before copying the formula across a live sheet.
Test more than one condition with AND and OR
Use AND when every condition must be true, and OR when at least one condition must be true. These functions fit inside the first argument of IF. They help keep a rule readable when a decision depends on two or more facts.
Suppose B2 contains an order quantity of 12 and C2 contains Yes to indicate that the customer is eligible for a promotion. With both conditions required, enter this in D2:
With quantity in B2 and promotion eligibility in C2, use =IF(AND(B2>=10,C2="Yes"),"Discount","Standard price"). For B2 equal to 12 and C2 equal to Yes, it returns Discount. If either test is false, it returns Standard price.
For an either-or rule, suppose D2 contains a priority label and E2 contains the number of days an issue has been open. Enter =IF(OR(D2="Urgent",E2>3),"Escalate","Normal queue"). It returns Escalate if the label is Urgent or the issue has been open for more than three days; both conditions do not have to be true. Keep the meaning of each test explicit, especially when mixing AND and OR, because the choice changes the rule.
Handle several outcomes with nested IF or IFS
When a decision has more than two outcomes, one option is to place an IF inside another IF. This is called a nested IF. For example, if A2 contains a score of 84 and you want to distinguish scores of 90 or higher, 80 or higher, and lower than 80, enter:
With the score in A2, use =IF(A2>=90,"A",IF(A2>=80,"B","Below B")). For a score of 84, the first test is false and the second is true, so the result is B. Nested IF formulas can handle more cases, but each additional layer makes the formula harder to inspect and easier to mis-order.
Google Sheets also has IFS, which checks conditions in sequence and returns the value associated with the first true condition. With a score of 92 in A2, use =IFS(A2>=90,"A",A2>=80,"B",A2>=70,"C",A2>=60,"D",TRUE,"F"). It returns A. The final TRUE acts as a catch-all, so a result is supplied even when none of the score thresholds match. Put more restrictive or higher thresholds first: once a condition is true, later conditions are not used.
Choose nested IF when there are only a few branches or when the logic has a natural hierarchy. Choose IFS when a sequence of separate tests is easier to read. For a long, changeable set of categories, a lookup table may be simpler to maintain than a very long formula.
Deal with blanks and missing values
A blank input can accidentally be treated like a number in a comparison. For example, an empty score cell may be interpreted as zero in some comparisons, causing a formula to display Fail even though nobody has entered a score. If blank means not yet assessed, test for it first.
With the score in A2, enter =IF(A2="","Not entered",IF(A2>=60,"Pass","Fail")). If A2 is empty, it returns Not entered; with 74 in A2, it returns Pass. Testing for a blank first prevents the score test from assigning a category to missing data. A formula that returns an empty string may also appear blank, so consider whether that should count as missing in your sheet.
To handle a possible error from another calculation, use IFERROR. For example, with a lookup value in A2 and a two-column lookup table in F2:G20 where the matching value is in the first column, use =IFERROR(VLOOKUP(A2,$F$2:$G$20,2,FALSE),"Not found"). If the lookup succeeds, the formula returns the corresponding value from the second column; if it produces an error, the cell displays Not found. IFERROR can make a sheet easier to read, but it can also conceal a broken reference or an unexpected data problem. Use a specific message and investigate recurring errors rather than hiding every issue without review.
Apply the formula to a column
For a short list, enter the formula in the first result row and use the fill handle, the small square at the bottom-right corner of the selected cell, to copy it down. Relative references adjust as the formula moves: a reference to A2 becomes A3 in the next row. If a reference must stay fixed, add dollar signs, as in $F$2:$G$20.
Google Sheets also supports ARRAYFORMULA for returning results across a range. Suppose names are in A2:A and scores are in B2:B. Put this formula in C2, leaving the cells below it in column C clear for the results:
With names in A2:A and scores in B2:B, enter =ARRAYFORMULA(IF(A2:A="","",IF(B2:B>=60,"Pass","Fail"))) in C2. A row with a name and a score of 74 displays Pass; rows without a name remain visually blank. The formula can fill results down the column automatically. If cells in its output area already contain data, it cannot expand into them, so clear that area before using it.
Common IF formula problems
If a formula is rejected or gives an unexpected result, check the condition, the quotation marks, and the order of the outcomes. A formula such as =IF(A2>=60,Pass,Fail) is missing quotation marks around text values; Sheets may interpret those words as named ranges or report an error. Text results need quotation marks, but a cell reference such as A2 and a number such as 60 do not.
Also check these frequent causes:
- Wrong comparison:
>excludes a value equal to the threshold, while>=includes it. - Reversed outcomes: The second argument is returned when the condition is true; the third is returned when it is false.
- Unexpected spaces: Text copied from another source may include extra spaces or nonprinting characters.
- Wrong cell references: A copied formula may shift references. Use dollar signs for references that should remain fixed.
- Locale separators: Many Sheets locales use commas between arguments, but some use semicolons. If Sheets rejects an otherwise valid formula, check the spreadsheet locale and use the separator it expects.
Google Sheets formulas begin with an equals sign. When writing a formula into a cell, type it directly into the cell or formula bar and press Enter. If the cell displays the formula text instead of its result, check that it begins with = and that the cell is not formatted as plain text. Changing the number format to Automatic and re-entering the formula can resolve that case.
IF compared with alternatives
Use IF when a cell needs to return one of two results based on a condition. Use IFS when several ordered conditions produce different outcomes, and AND or OR when a single decision depends on multiple tests. Use IFERROR when the purpose is specifically to provide a fallback for a calculation that may return an error.
For repeated categories or thresholds that change regularly, a small reference table can be easier to update than a long nested formula. A lookup formula can retrieve the appropriate category from that table. Conditional formatting is another alternative when the goal is only to change a cell’s appearance, such as highlighting low stock; it does not return a text label or calculation. In Google Sheets, its menu path is Format > Conditional formatting.
Excel has an IF function with the same general purpose and a very similar formula structure, so basic IF logic is often portable between the two programs. However, separators can vary with locale, and more complex features or surrounding spreadsheet behavior may differ. Check a formula after moving a sheet between Google Sheets and Excel rather than assuming every function or feature is identical.
Frequently Asked Questions
Does Google Sheets have an IF function?
Yes. Enter =IF(condition,value_if_true,value_if_false) in a cell, replacing the examples with a test and the two results you want. The function returns the second argument when the condition is true and the third when it is false.
Can an IF statement have more than two outcomes?
Yes. Nest IF functions, use IFS to test multiple conditions in order, or use a lookup table when there are many categories. For nested IF or IFS, arrange conditions so a broader test does not catch a value before the intended, more specific test.
How do I write IF with multiple conditions?
Put AND or OR inside IF’s condition. AND requires all its tests to be true; OR requires at least one. Then set the true and false results in the usual IF arguments.
How do I make an IF formula return a blank?
Use an empty string, written as two quotation marks, as one of the results. For example, a blank-check formula can return "" when its input is empty. The cell looks blank, although it still contains a formula.
Why does my IF formula show an error?
Check that the formula starts with an equals sign, text values have quotation marks, parentheses are balanced, and the argument separator matches your spreadsheet locale. Also verify that referenced cells contain the expected type of data, such as a real date rather than text that only looks like a date.
Related
- Keep Numbers as Text in Excel: A Step-by-Step Guide
- How to Freeze the First Two Rows in Excel While Scrolling
- Keep Color Formatting in Excel While Editing Data
Try it: the Date Difference Calculator: days, months, years and weekdays between two dates, with the DATEDIF formulas.
More in How-to basics
- Outlook Shared Mailbox Rules: How to Create ThemTo create rules for an Outlook organization mailbox, open the shared mailbox in Outlook on the web, then…
- Can You Put Text With a Checkbox in Google Sheets?Yes—but a Google Sheets checkbox does not display ordinary text inside its box. Put the label in a…
- Freeze an Entire Column in Excel: A Step-by-Step GuideTo keep a column visible while you scroll across a worksheet in Excel for Microsoft 365 on Windows,…
- Best Way to Make a Schedule in Google Sheets: A GuideFor most people, the best way to make a schedule in Google Sheets is to build a simple…
- Outlook View Changes: Can You Lock the Layout?Outlook does not provide a universal “Lock View” switch that makes a mail layout impossible to change. You…
- How to Double Space in Word: Shortcut and StepsTo double-space text in Microsoft Word for Microsoft 365 on Windows, select the text or paragraphs and press…
Sources: Function behaviour and menu paths: Microsoft Support documentation for Excel. Method & sources
Spotted an error in this guide? Let us know.