Going Stellar

Home/Google Sheets reference

Google Sheets function · Logical

IF in Google Sheets: syntax and examples

IF runs a test and returns one result when it is TRUE and another when it is FALSE. Combine it with AND, OR and ARRAYFORMULA for multi-condition checks over whole columns.

Syntax

IF(logical_expression, value_if_true, value_if_false)

Arguments

ArgumentTypeRequiredWhat it does
logical_expressionbooleanyesThe test. Anything that evaluates to TRUE or FALSE, such as B2>0.
value_if_trueanyyesWhat to return when the test is TRUE.
value_if_falseanynoWhat to return when the test is FALSE. If left out, a false test returns FALSE.

Examples

The examples use this table, starting in A1:

ItemStockPrice
Lamp1279.9
Chair0549
Stand7129.5
Tray4034
=IF(B2>0, "In stock", "Sold out")

Result: In stock

A basic yes or no label based on a number.

Run in a Google Sheet (English US locale) on .

=IF(B3>0, "In stock", "Sold out")

Result: Sold out

The same formula on the row with zero stock.

Run in a Google Sheet (English US locale) on .

=IF(C2>100, "Premium", IF(C2>50, "Mid", "Budget"))

Result: Mid

Nested IF: the second IF runs only when the first test is false, giving three tiers.

Run in a Google Sheet (English US locale) on .

=IF(AND(B4>0, C4<150), "Offer", "Skip")

Result: Offer

AND inside the test: both conditions must hold for TRUE.

Run in a Google Sheet (English US locale) on .

=ARRAYFORMULA(IF(B2:B5>0, "ok", "empty"))

Result:

ok
empty
ok
ok

With ARRAYFORMULA one IF runs over the whole column and returns one label per row.

Run in a Google Sheet (English US locale) on .

Common errors

  • If you leave out value_if_false and the test fails, the cell shows FALSE, not an empty cell. Write "" as the third argument for a blank.
  • IF takes three arguments at most. A fourth argument is not another branch: the formula returns #N/A. Nest a second IF, or use IFS for many branches.
  • A number works as a test: 0 counts as FALSE and any other number as TRUE.
  • Over a range, a plain IF returns #VALUE!. Wrap it in ARRAYFORMULA to get one result per row.

Compared with Excel

Same syntax as Excel IF. In Excel 365 a range in the test spills on its own, while Google Sheets needs ARRAYFORMULA.

Sources

  1. IF (Docs Editors Help)

Markdown version · All functions