Master the IF Function in Google Sheets: Beyond the Basics

Published on

The IF function in Google Sheets allows you to compare a value with what you expect, called a logical expression. This expression can result in either TRUE or FALSE.

An example of a logical expression is =A1="Apple", which will return TRUE if A1 contains “Apple” and FALSE otherwise.

What makes the IF function more useful is its ability to return outputs based on the outcome of the logical expression. You can specify what value you want the function to return or what calculation it should perform if the expression is TRUE, and what it should return or do if it’s FALSE.

For more complex scenarios, you can use nested IF statements. This involves placing additional IF statements within the value_if_false argument of the previous IF statement. Nested IFs allow you to create formulas with multiple conditions.

Syntax: IF(logical_expression, value_if_true, value_if_false)

In this tutorial, we’ll check out the basics of the IF function and dive into using nested IF statements to really get the most out of conditional logic in Google Sheets.

Basic Examples

Enter the text “Sunday” in cell A1 and the following formula in cell B1:

=IF(A1="Sunday", "Blue")

It will return “Blue”. If you delete the value in cell A1 or enter any other text, the formula will return the default value, which is FALSE. This means the value_if_false argument is optional in the IF function in Google Sheets.

Basic example of IF function formula

Let’s see a different formula:

=IF(A1="Sunday", "Blue", "Grey")

This will return “Blue” if A1 is “Sunday”, otherwise it will return “Grey”.

Logical expressions can include comparison operators such as greater than (>), less than (<), not equal to (<>), greater than or equal to (>=), less than or equal to (<=), and equals (=) when working with numeric, date, or time values.

For example, the date in cell A1 is June 15, 2030. So the following formula will return “Operational”:

=IF(A1 <= DATE(2025, 12, 31), "Expired", "Operational")

The date function in the logical expression follows the syntax DATE(year, month, day).

In the following example, with the same date in cell A1, the formula will return ‘Operational’ until the current calendar date (as per the system) passes June 15, 2030:

=IF(A1 < TODAY(), "Expired", "Operational")

This formula checks if the date in cell A1 is before today’s date (TODAY()). If it is, it returns ‘Expired’; otherwise, it returns ‘Operational’.”

Nested IF Functions in Google Sheets

As mentioned earlier, nested IFs allow you to create formulas with multiple conditions. You can place additional IF statements within the value_if_false argument of the previous IF statement.

This is a very useful technique, and mastering it is essential, although there is a better alternative function for this called IFS.

You can understand how to use nested IF functions with the following syntax:

IF(logical_expression, value_if_true, IF(logical_expression, value_if_true, IF(logical_expression, value_if_true, value_if_false)))

Ensure the formula has closing brackets that match the number of nested IF functions or logical expressions.

Example:

Consider the following formula:

=IF(A1>80, "Diamond", IF(A1>50, "Platinum", IF(A1>30, "Silver", "Unknown")))

In this formula, there are three logical expressions and three closing brackets.

The formula returns:

  • “Diamond” if the value in cell A1 is greater than 80,
  • “Platinum” if the value in cell A1 is greater than 50 but not greater than 80,
  • “Silver” if the value in cell A1 is greater than 30 but not greater than 50,
  • “Unknown” if the value in cell A1 is 30 or less.

Examples of IF and ARRAYFORMULA Combination in Google Sheets

When you specify an array reference in the logical expression part of the IF function, you should use the ARRAYFORMULA function or other array functions alongside it in Google Sheets.

For example, the following formula will return the month number from the dates in A2:A:

=ArrayFormula(IF(A2:A<>"", MONTH(A2:A), ""))

It returns an empty string (“”) in empty rows.

Example of using IF and ARRAYFORMULA together in Google Sheets

If you see an array reference in logical expressions and no ARRAYFORMULA in use, that means it might be used within array functions such as INDEX, SORT, SORTN, or FILTER.

For example, you can replace the ARRAYFORMULA in the above formula with INDEX as follows:

=INDEX(IF(A2:A<>"", MONTH(A2:A), ""))

Resources

Prashanth KV
Prashanth KV
Your Trusted Google Sheets and Excel Guide Prashanth KV brings a wealth of experience in Google Sheets and Excel, cultivated through years of work with multinational corporations in Mumbai and Dubai. As a recognized Google Product Expert in Docs Editors, Prashanth shares his expertise through insightful blogging since 2012. Explore his blog for practical tips and guidance on maximizing your spreadsheet skills.

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Compare Two Tables for Differences in Excel

To compare two tables with similar data for differences, you can use the XLOOKUP...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

More like this

Highlight Upcoming Birthdays in Google Sheets

When highlighting upcoming birthdays in Google Sheets, one important aspect is ignoring the year...

Calculate Weighted Average in Pivot Table in Google Sheets

You can calculate a weighted average in a Pivot Table using a custom formula...

Summarize Data and Keep the Last Record in Google Sheets

In Google Sheets, we can summarize data (like sum, average, min, max, count) using...

8 COMMENTS

  1. 1. How can I copy-paste a formula with just the same one cell by not changing the formula if pasted?

    2. How to create an aging deducting the completion?

  2. When A1 is populated B1 should be auto-populated with today’s date. When I open the google spreadsheet tomorrow, B1 should still have today’s date.

    Is there a formula for this? I’m using a tablet to create Google Spreadsheet. Thanks!

  3. Hi!

    Congrats for this amazing site!

    I’m really a noob and would really appreciate you to help me with the issue below.

    1. There’s a column with different texts.
    2. I need to categorize every text with different specific tags in another column.
    3. For instance: if A2 contains “WordA” then write “A” in B2; if A2 contains “WordB” then write “B” in B2, and so on (up to 10 different tags).

    Is this possible?

    Thanks in advance!

    • Welcome!

      I am glad to hear that you liked this site.

      Regarding the problem, you can use IF, IFS or CHOOSE. I prefer the function CHOOSE here. Try this formula in cell B2.

      =switch(A2,"WordA","A","WordB","B","WordC","C")

      You can easily add more conditions to it.

      For an entire column range A2:A, just apply the below formula in B2.

      =iferror(switch(A2:A,"WordA","A","WordB","B","WordC","C"))

      Thanks!

    • Hi Sangita,

      Welcome to Info Inspired!

      Here is a sample formula.

      =query(iferror(GOOGLEFINANCE(“NSE:HDFCBANK”,”volume”,DATE(2018,4,1), DATE(2018,4,10), “DAILY”)),”Select Avg (Col2)”,1)

      I think this formula can find the average volume of the provided ticker. You can change the ticker and date duration.

      Note:
      1. Please re-type the double quotes in formula.
      2. Learn Googlefinance function.
      Thanks.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.