Google Sheets Tips

IF function in Google Sheets: formula, IF with AND and OR, nested IF

IF returns one value when a condition is true and another when it is false. This guide works every IF formula on one marketing question, which campaigns spend more than they earn: conditions on numbers, text, blanks and dates, IF with AND and OR, nested IF and IFS, IF across a column, and the mistakes that produce wrong results without an error.

Google Sheets TipsVadym KramarenkoVadym KramarenkoGrowth Marketing ManagerVadym Kramarenko is a Growth Marketing Manager at OWOX, where he drives user acquisition and product-led growth strategies. He hosts the OWOX podcast, interviewing analytics professionals about data-driven marketing, attribution, and reporting best practices. Vadym specializes in turning complex analytics concepts into practical, actionable marketing frameworks.All articles →16 min read

IF function in Google Sheets: formula, IF with AND and OR, nested IF

The IF function checks a condition and returns one value when it is true and another when it is false:

=IF(E2 < D2, "Losing", "Earning")

If the revenue in E2 is lower than the spend in D2, the formula returns Losing; otherwise it returns Earning.

You need Formula
Two conditions that both have to be true =IF(AND(ISNUMBER(E2), E2 < D2, C2 < DATE(2026, 10, 1)), "Cut", "Keep")
Either of two conditions =IF(OR(E2 < D2, F2 = "Paused"), "Review", "OK")
Three or more outcomes =IFS(NOT(ISNUMBER(E2)), "No data", E2 < D2, "Losing", E2 < D2 * 3, "Thin", TRUE, "Strong")
A check for an empty cell =IF(E2 = "", "No data", E2 - D2)
A condition on a date =IF(C2 >= DATE(2026, 10, 1), "New", "Established")
The same IF for a whole column =ARRAYFORMULA(IF(ISNUMBER(E2:E11), IF(E2:E11 < D2:D11, "Losing", "Earning"), "No data"))

This guide works every formula on one question a CMO asks about the marketing mix: flag every campaign that spends more than it earns. It is “are we losing money in this campaign?” asked of the whole list at once, and the answer is one IF formula copied down a column. Getting there shows why the first IF you write usually flags the wrong campaigns: on the ten campaigns below, the same question flags 4, 3 or 5 of them, depending on what the formula treats as revenue and what it does with a missing number.

The question and the sheet

The question and the sheet

The data is a campaign report for one month, November 2026: one row per campaign, from row 2 to row 11, with the headers in row 1.

Column Holds
A Campaign name
B Channel: Paid search, Paid social, Video, Email, Affiliate or Display
C Start date of the campaign
D Spend in the month
E Revenue the store attributes to the campaign in the month
F Status: Active or Paused

It has the faults a real report has. The revenue cell of bf_teaser is empty, because the campaign started on November 3 and its orders are not attributed yet. The revenue cell of affiliate_q4 says “No data”, typed in by hand because the affiliate network’s report did not arrive. newsletter_promo cost nothing in media, so its spend is $0.

Google Sheets campaign report with ten campaigns, columns for campaign, channel, start date, spend, revenue and status, and the formula =IF(ISNUMBER(E2), IF(E2 < D2, “Losing”, “Earning”), “No data”) in G2. Column G flags generic_search, prospecting_lal and video_awareness as Losing and bf_teaser and affiliate_q4 as No data; a summary on the right counts 3 Losing campaigns with $7,450 of spend, 5 Earning with $5,640 and 2 with no data with $2,700.

The finished answer is column G, and the formula in the bar is the whole of it:

=IF(ISNUMBER(E2), IF(E2 < D2, "Losing", "Earning"), "No data")

Flag Campaigns Spend Revenue
Losing 3: generic_search, prospecting_lal, video_awareness $7,450 $5,340
Earning 5 $5,640 $17,670
No data 2: bf_teaser, affiliate_q4 $2,700 –
Total 10 $15,790 $23,010

Three campaigns spend more than they bring in, and $7,450 of the month’s $15,790 goes to them. Two more cannot be judged yet, and they stay on the list as their own line instead of being counted as winners or losers. The rest of this guide builds that formula from the simplest IF up, and then shows the two other answers the same sheet gives.

IF function syntax

IF function syntax

IF is the basic conditional formula in Google Sheets. The if condition goes first, then the two results:

=IF(logical_expression, value_if_true, value_if_false)

  • logical_expression: a test that is either TRUE or FALSE, usually a comparison with = (equal), <> (different from), > (greater than), < (less than), >= (greater than or equal to) or <= (less than or equal to). In E2 < D2 the logical expression asks whether revenue is below spend. AND, OR, NOT, ISNUMBER and ISTEXT are logical expressions too: each returns TRUE or FALSE.
  • value_if_true: what to return when the test is TRUE: a number, text in quotes, a cell reference or another formula.
  • value_if_false (optional): what to return when the test is FALSE. If you leave it out, the formula returns FALSE in that case.

The textbook example is a score: =IF(B2 >= 50, "Pass", "Fail") returns Pass for 50 or more and Fail for anything less. The campaign flag is the same pattern with spend in place of the pass mark.

Text has to be in double quotes. =IF(E2 < D2, Losing, Earning) returns #NAME?, because Sheets reads Losing and Earning as names of something it does not know.

A campaign with revenue not yet in gets flagged as losing money.

write me an IF formula for my sheet that labels each row by my conditions, handles blanks and dates, and fills the whole column with ARRAYFORMULA

IF with numbers, blanks and text

IF with numbers, blanks and text

A calculation as the result

The two results do not have to be labels. To see how much each campaign lost, return the gap between spend and revenue when revenue is lower, and 0 otherwise:

=IF(E2 < D2, D2 - E2, 0)

Copy the formula down the column to apply it to every campaign. It returns $470 for generic_search and $1,210 for video_awareness. =IF(E2 < D2, "Losing", "Earning") is the same IF function in Google Sheets with text as the two results: the if then logic is “if this test holds, then return this, else return that”.

Empty cells

Copied down without a guard, the simple formula gets the two incomplete rows wrong, and gets them wrong in opposite directions:

Google Sheets with the formula =IF(E7 < D7, “Losing”, “Earning”) in G7. Row 7, bf_teaser, has an empty revenue cell and is flagged Losing; row 10, affiliate_q4, has the text No data in its revenue cell and is flagged Earning.

bf_teaser has no revenue yet, and an empty cell compares as 0, so it is flagged Losing. affiliate_q4 holds the text “No data”, and text compares as greater than any number, so it is flagged Earning. Neither label is true; both are guesses the formula made without saying so.

To find empty cells before they turn into a wrong number, compare the cell with an empty string:

=IF(E2 = "", "No data", E2 - D2)

This returns No data for bf_teaser and the net result for the other rows: $5,640 for brand_search, −$470 for generic_search. =IF(ISBLANK(E2), "No data", E2 - D2) does the same for truly empty cells. The comparison with “” also catches cells that hold a formula returning an empty string, which ISBLANK does not. The reverse test, if not empty, is E2 <> "".

Row 10 still fails: “No data” minus $1,100 is #VALUE!, because the cell is not empty, it holds text.

Text

A text condition compares the cell with a string in quotes:

=IF(E2 = "No data", "Missing report", E2 - D2)

This IF function with text returns Missing report for affiliate_q4. The comparison ignores case: “no data” and “No data” are equal. For a case-sensitive test, use EXACT: =IF(EXACT(E2, "No data"), ...). Notice that this formula now lets the empty bf_teaser row through as a $1,600 loss: each test catches one kind of gap. The answer formula uses ISNUMBER, which catches both (more on it below).

The same kind of test works on any text column. On the status column, =IF(F2 = "Paused", "No action", "Check") returns No action for display_remarketing only.

Nested IF: more than two outcomes

Nested IF: more than two outcomes

For three or more outcomes, put another IF into the value_if_false of the first one. To grade every campaign with revenue as Losing (revenue below spend), Thin (revenue below three times spend) or Strong (the rest):

=IF(NOT(ISNUMBER(E2)), "No data", IF(E2 < D2, "Losing", IF(E2 < D2 * 3, "Thin", "Strong")))

On the ten campaigns this gives 3 Losing, 2 Thin (shopping_feed and display_remarketing), 3 Strong (brand_search, retargeting_dpa and newsletter_promo) and 2 No data.

The conditions are checked in order, and the first one that is true decides the result. That is why the third IF only needs E2 < D2 * 3: it is reached only when revenue is at least equal to spend. This is how a nested IF handles multiple conditions in one formula.

The IFS function writes the same logic as a flat list of condition and result pairs:

=IFS(NOT(ISNUMBER(E2)), "No data", E2 < D2, "Losing", E2 < D2 * 3, "Thin", TRUE, "Strong")

The final TRUE is the “everything else” case. Without it, IFS returns #N/A when no condition matches.

IF with AND and OR

IF with AND and OR

AND: all conditions true

AND returns TRUE only when every condition inside it is true. A campaign that started in October has not had time to learn, so a sensible cut list asks for three things at once: revenue is a number, revenue is below spend, and the campaign started before October 1, 2026:

=IF(AND(ISNUMBER(E2), E2 < D2, C2 < DATE(2026, 10, 1)), "Cut", "Keep")

Google Sheets with the formula =IF(AND(ISNUMBER(E2), E2 < D2, C2 < DATE(2026, 10, 1)), “Cut”, “Keep”) in G2. generic_search and video_awareness are marked Cut; every other campaign, including prospecting_lal, which started on October 1, is marked Keep.

Two campaigns are marked Cut, generic_search and video_awareness, with $5,300 of spend between them. prospecting_lal loses money too, but it started on October 1 and stays on Keep. Writing IF and AND together this way is how Google Sheets handles an if statement with multiple conditions, or two conditions that are true at the same time.

OR: at least one condition true

OR returns TRUE when any of its conditions is true. To list every campaign worth a look, losing money or paused:

=IF(OR(E2 < D2, F2 = "Paused"), "Review", "OK")

It returns Review for five campaigns: generic_search, prospecting_lal, video_awareness, display_remarketing (paused) and bf_teaser, which is on the list only because its empty revenue cell compares as 0. The guard from the previous section belongs inside an OR as much as inside an IF.

OR is also the way to test one cell against several values: =IF(OR(B2 = "Paid search", B2 = "Paid social"), "Paid", "Other") marks six of the ten campaigns as Paid.

AND and OR together

The two can be nested. This formula sends a campaign to review when it is an established campaign losing money, or when it is paused:

=IF(OR(AND(ISNUMBER(E2), E2 < D2, C2 < DATE(2026, 10, 1)), F2 = "Paused"), "Review", "Keep")

Read it from the inside: AND covers the first rule, and OR adds the second one as an alternative. It returns Review for generic_search, video_awareness and display_remarketing.

IF with dates

IF with dates

Compare a date cell with a date built by the DATE function. To mark the campaigns that started in October or later as new:

=IF(C2 >= DATE(2026, 10, 1), "New", "Established")

Three campaigns are New: prospecting_lal, bf_teaser and affiliate_q4.

Do not write the date as text in the comparison. =IF(C2 = "3/2/2026", "yes", "no") returns “no” even when C2 holds that date, because a date is a number and the quoted value is text. For today’s date, use TODAY(): =IF(C2 > TODAY() - 30, "Too early to judge", "Judge") gives every campaign younger than 30 days a grace period that moves by itself.

IF with other functions

IF with other functions

ISTEXT and ISNUMBER: test the type of a cell

=IF(ISTEXT(E2), "Check the source", IF(ISNUMBER(E2), "Has revenue"))

  • ISTEXT(E2): TRUE when the revenue cell holds text such as “No data”.
  • ISNUMBER(E2): TRUE when it holds a number.

This returns Check the source for affiliate_q4 and Has revenue for eight campaigns. An empty cell is neither text nor a number, so the formula returns FALSE for bf_teaser. Add a third value, or test for the number first, as the answer formula does: IF(ISNUMBER(E2), …, "No data") treats an empty cell and a text cell the same way, because neither can be compared with spend.

A whole column with ARRAYFORMULA

Inside ARRAYFORMULA, IF takes ranges and returns a result for every row:

=ARRAYFORMULA(IF(ISNUMBER(E2:E11), IF(E2:E11 < D2:D11, "Losing", "Earning"), "No data"))

One formula in G2 fills the column with the same ten flags as the first image. All ranges in it have to cover the same rows. AND and OR do not work row by row inside ARRAYFORMULA; multiply the conditions for AND and add them for OR. The cut list for the whole column is:

=ARRAYFORMULA(IF(ISNUMBER(E2:E11) * (E2:E11 < D2:D11) * (C2:C11 < DATE(2026, 10, 1)), "Cut", "Keep"))

Conditional sums and counts

To add up the spend of the campaigns that lose money, IF can be combined with SUM:

=SUM(ARRAYFORMULA(IF(ISNUMBER(E2:E11), IF(E2:E11 < D2:D11, D2:D11, 0), 0)))

It returns $7,450. IF returns the spend for the rows that meet the condition and 0 for the others, and SUM adds them. Once the flags are in column G, SUMIF is shorter and gives the same total: =SUMIF(G2:G11, "Losing", D2:D11). For a single condition on a date, =SUMIF(C2:C11, "<" & DATE(2026, 10, 1), D2:D11) returns $10,940, the spend of the campaigns that started before October, the same as =SUM(ARRAYFORMULA(IF(C2:C11 < DATE(2026, 10, 1), D2:D11, 0))).

IF can also react to a count. This formula checks whether every campaign has a revenue number before anyone reads the flags:

=IF(COUNT(E2:E11) = ROWS(E2:E11), "All campaigns have revenue", "Revenue missing for " & (ROWS(E2:E11) - COUNT(E2:E11)) & " campaigns")

COUNT counts the cells of E2:E11 that hold numbers, 8 here, so the formula returns “Revenue missing for 2 campaigns”. To count the cells that meet a condition, use COUNTIF: =COUNTIF(G2:G11, "Losing") returns 3.

One question, three answers

One question, three answers

“Spends more than it earns” sounds like one test. On this sheet it is three, they give different answers, and each one is arithmetically correct:

Google Sheets with three flag columns side by side and the formula =IF(ISNUMBER(E2), IF(E2 * 0.4 < D2, “Losing”, “Earning”), “No data”) in I2. The column without a guard flags 4 campaigns with $9,050 of spend, the revenue rule flags 3 with $7,450, and the margin rule flags 5 with $10,910.

  • No guard, =IF(E2 < D2, "Losing", "Earning"): 4 campaigns, $9,050 of spend. It counts the empty bf_teaser as a loser and the unreported affiliate_q4 as a winner.
  • Revenue rule, the answer formula: 3 campaigns, $7,450 of spend, and 2 marked No data.
  • Margin rule, =IF(ISNUMBER(E2), IF(E2 * 0.4 < D2, "Losing", "Earning"), "No data"): 5 campaigns, $10,910 of spend. Revenue is not what the store keeps. At a 40% gross margin, shopping_feed brings in $4,050 and keeps $1,620 against $2,700 of spend, and display_remarketing keeps $456 against $760. Both bring in more revenue than they cost and still lose money.

None of the three is a formula error. Which one is “losing money” depends on whether the business counts revenue or margin, and what it does with a campaign it cannot measure yet. Those are decisions, not syntax: write the one you used next to the flag, because the CMO who moves budget on it needs to know.

Mistakes and errors in IF formulas

Mistakes and errors in IF formulas

⚠️ Error: The formula returns FALSE.

✅ Solution: The condition is false and there is no third argument. Add the value to return in that case, or "" to leave the cell empty.

⚠️ Error: #NAME?

✅ Solution: A text value is not in quotes, or a function name is misspelled.

⚠️ Error: The comparison with a number gives the wrong answer.

✅ Solution: The cell holds the number as text, which happens when revenue is pasted from another report. Text counts as greater than any number, so ="10" > 5 is TRUE, and so is ="1" > 5. If generic_search’s revenue arrived as the text “2980”, E3 < D3 would be FALSE and a losing campaign would be flagged Earning. Convert the cell with VALUE or fix the source data.

⚠️ Error: #VALUE!

✅ Solution: The first argument is text that is not a condition, for example =IF("abc", ...), or the result does arithmetic on text, as E2 - D2 does on the “No data” row. The test has to be a comparison or a value that is TRUE, FALSE or a number.

⚠️ Error: #DIV/0! or #N/A inside the IF.

✅ Solution: An error in the condition or in the returned value passes through IF. Return on ad spend, =E9 / D9, is #DIV/0! for newsletter_promo, which spent $0. Test the cause first: =IF(D2 = 0, "No spend", E2 / D2): when D2 is 0, IF returns “No spend” and the division never reaches the cell. IFERROR or IFNA around the part that produces the error silences it, =IF(IFERROR(E2 / D2, 0) > 1, "Above", "Below"), but that formula calls newsletter_promo Below and hides every other error too, the #VALUE! on the “No data” row included.

⚠️ Error: A nested IF returns the wrong label.

✅ Solution: The conditions are in the wrong order. The first true condition wins, so start with the narrowest one, or rewrite the formula with IFS. =IFS(E2 < D2 * 3, "Thin", E2 < D2, "Losing", TRUE, "Strong") labels all five campaigns with revenue below three times spend as Thin, the three losing ones included, because the wider test comes first.

⚠️ Error: The flag is right and does not match the ad platform.

✅ Solution: The formula compares the numbers it is given. Google Ads or Meta may report a campaign as profitable while the sheet flags it Losing, because the platform counts its own conversion value and the store counts orders it attributes to the campaign. Check the period and time zone of the month, refunds (gross or net revenue), the attribution rule, revenue against margin, and rows with no revenue. Each is a definition to agree on and write next to the number.

Related Google Sheets functions

Functions that are often used with or instead of IF, each with its own guide:

  • IFS: Several conditions and results in one flat formula.
  • VLOOKUP with IF: Test the value a lookup returns, or choose the table to search.
  • COUNTIF and COUNTIFS: Count the cells that meet conditions.
  • SUM, SUMIF and SUMIFS: Add up the cells that meet conditions.
  • FILTER: Returns the rows that meet a condition, such as every campaign flagged Losing.
  • QUERY with UNIQUE: Combines SQL-like filtering with deduplication to return only the distinct rows that match a condition.
  • Data validation: Restricts what can be entered in a cell with rules and drop-down lists, so “No data” cannot be typed into a revenue column.
  • Pivot tables: Summarize a table by category without formulas.

Business rules written as IF formulas need a single home

Business rules written as IF formulas need a single home

An IF formula is often a business rule in disguise: what counts as a qualified lead, which orders are “large”, when a campaign is “losing”. Typed into one spreadsheet, the rule lives in that file only. The next report gets its own copy, with revenue where this one has margin, and the two no longer agree. And the formula is exact; the rows may not be. If the revenue column was pasted from three platform exports last Monday, the flags are right for numbers that are already out of date.

The OWOX Data Marts extension for Google Sheets covers that half. A data analyst publishes a Data Mart (a table or an SQL query in your data warehouse, with the definitions the team agreed, such as which attribution rule credits a campaign or whether revenue is net of refunds) and makes it available for reports. In Sheets you open the extension, pick the Data Mart, tick the columns you want and run it. The rows land in a tab, ready for your formulas.

Google Sheets with the OWOX Data Marts extension open beside an ad spend table: the Unified Ad Spend Data Mart, nine of fourteen columns ticked and a Save & Run button – the rows in the sheet come from a governed Data Mart, not a pasted export

What changes for the person who maintains the sheet:

  • Refresh replaces re-export. Refresh current report in the extension menu re-runs the same pull, and a scheduled refresh keeps the tab current without anyone touching it.
  • The source is written on the sheet. The header cell of an imported tab carries a note with the Data Mart it came from, the time of the import and a link to the report.
  • No SQL and no data warehouse access needed. The analyst decides which Data Marts and columns are available. You choose from that list.

The extension does not write or change the analyst’s SQL. A rule that is defined there once, such as margin per campaign, reaches every sheet as a ready column, the same in each report, and IF is left for the logic that belongs to one sheet. The extension comes with the OWOX Cloud plans of OWOX Data Marts; spreadsheet reporting describes both ways data reaches a sheet.

write me an IF formula for my sheet that labels each row by my conditions, handles blanks and dates, and fills the whole column with ARRAYFORMULA

FAQ

Frequently Asked Questions

How do I create nested IF statements for complex conditions in Google Sheets?

Put another IF in the value_if_false of the first one. To grade campaigns as Losing, Thin or Strong, use `=IF(NOT(ISNUMBER(E2)), "No data", IF(E2 < D2, "Losing", IF(E2 < D2 * 3, "Thin", "Strong")))`, with spend in D and revenue in E. The conditions are checked in order and the first true one decides the result, so put the narrowest test first. On a ten-campaign report this gives 3 Losing, 2 Thin, 3 Strong and 2 No data. IFS writes the same logic as a flat list of condition and result pairs, ending with TRUE for everything else.

How can I apply conditional formatting using the IF function in Google Sheets?

You do not need IF inside the rule. Select the range, open conditional formatting, choose a custom formula and enter the condition itself, for example `=$E2 < $D2` to colour every campaign whose revenue in column E is below its spend in column D. The rule applies the format wherever the condition is TRUE, and the dollar signs fix the columns, so the whole row is highlighted. Add `ISNUMBER($E2)` with AND, `=AND(ISNUMBER($E2), $E2 < $D2)`, so rows with no revenue yet are not coloured as losses.

Can I use the IF function to identify blank or non-blank cells?

Yes. `=IF(E2 = "", "No data", E2 - D2)` returns No data when the revenue cell is empty and the campaign's net result when it is not; `E2 <> ""` tests for a non-blank cell. `=IF(ISBLANK(E2), "No data", E2 - D2)` works for truly empty cells, while the comparison with "" also catches formulas that return an empty string. Test for blanks before comparing numbers: an empty revenue cell counts as 0, so `=IF(E2 < D2, "Losing", "Earning")` flags a campaign with no revenue reported yet as Losing.

How can I use the IF function to check for numerical values in Google Sheets?

Combine IF with ISNUMBER. `=IF(ISNUMBER(E2), IF(E2 < D2, "Losing", "Earning"), "No data")` compares revenue with spend only when the revenue cell holds a number, and returns No data for an empty cell or for text such as "No data" typed in by hand. Without the check, text counts as greater than any number, so a campaign whose revenue was never reported is flagged Earning. On a ten-campaign report the guarded formula flags 3 campaigns as Losing and keeps 2 as No data.

What is the syntax of the IF function in Google Sheets?

The syntax is `=IF(logical_expression, value_if_true, value_if_false)`. The logical_expression is a test that returns TRUE or FALSE, such as `E2 < D2` (revenue below spend). The value_if_true is what the formula returns when the test is TRUE, and the value_if_false is what it returns otherwise; if you leave the last argument out, the formula returns FALSE. Text results go in double quotes: `=IF(E2 < D2, "Losing", "Earning")` flags a campaign that spends more than it earns.

Who wrote this

Vadym Kramarenko Growth Marketing Manager

Vadym Kramarenko is a Growth Marketing Manager at OWOX, where he drives user acquisition and product-led growth strategies. He hosts the OWOX podcast, interviewing analytics professionals about data-driven marketing, attribution, and reporting best practices. Vadym specializes in turning complex analytics concepts into practical, actionable marketing frameworks.