IF Function in☝️ Google Sheets Explained (Definition, Syntax, How to Use It, Examples)

This guide covers everything you need to know about the Google Sheets IF function, including its definition, syntax, use cases, and how to use it.

What is the IF Function? How Does It Work?

The IF function function in Google Sheets returns one value if a given logical expression is TRUE and another if it’s FALSE. Simply put, the IF function acts like a mini decision-making machine in your Google Sheets. It analyzes a given situation (the logical expression) and decides whether the situation is true or false, returning the corresponding value.

Using the IF function, you can set up complex criteria within your spreadsheet, seamlessly toggling between two outcomes based on the validity of a specific condition. This function is particularly useful when categorizing data, performing calculations, or generating results based on variable inputs or conditions.

For instance, if you have a list of sales figures, you could use the IF function to automatically categorize each figure as “Above Average” or “Below Average”, depending on whether it’s higher or lower than the average sales figure. Similarly, the IF function can return specific text, calculations, or cell references based on particular conditions.

Remember, the IF function only allows for two possible outcomes – one if the condition is true and another if it’s false. If you need to test for more than two conditions, you have to use nested IF functions or explore other functions like IFS or SWITCH.

IF Syntax

The syntax and arguments for the function are as follows:

IF(logical_expression, value_if_true, value_if_false)

Where:

  • logical_expression: This refers to an expression or a reference to a cell containing an expression representing a logical value. The logical value can be either TRUE or FALSE. This is a required argument for the IF function.
  • value_if_true: This is the value the function will return if the logical_expression evaluates to TRUE. This is also a required argument for the IF function.
  • value_if_false: This is an optional argument. If provided, the function will return this value if the logical_expression evaluates to FALSE. The function will return blank by default if this argument is not provided.

Usage notes related to syntax and arguments:

  • The IF function evaluates the logical_expression argument first. If the logical_expression is TRUE, it returns the value_if_true. If the logical_expression is FALSE and the value_if_false is provided, it returns the value_if_false. If the value_if_false is not provided, it returns blank.
  • The logical_expression argument can be any expression that results in a TRUE or FALSE output. This can include comparisons using operators like =, <, >, <=, >=, <>, and functions that return a logical value, like ISNUMBER, ISBLANK, and ISTEXT.
  • The value_if_true and value_if_false arguments can be any value or expression that Google Sheets can evaluate. This includes numbers, text, dates, and other functions.
  • The IF function can be nested within itself to test multiple conditions.
  • The IF function is not case-sensitive. For example, IF(“A”=”a”,1,0) will return 1, because “A” and “a” are considered equal.
  • The IF function will return an error if the logical_expression argument is not provided.

Examples of How to Use the IF Function

Here are some practical examples of how to use the IF function in Google Sheets:

Example #1: Basic IF Function

Suppose you have a list of students and their grades and want to determine whether each student passed or failed. If the passing grade is 65, you can use the IF function as follows:

=IF(B2>=65, “Pass”, “Fail”)

In this case, B2 is the cell that contains the student’s grade. If the grade in B2 is greater than or equal to 65, the function will return “Pass”. If not, it will return “Fail”.

Example #2: Nested IF Function

Let’s consider a scenario where you have a list of numbers in column A and want to categorize them as “Small”, “Medium”, or “Large”. You can use a nested IF function to achieve this:

=IF(A2<10, “Small”, IF(A2<20, “Medium”, “Large”))

Here, the function first checks if the number in A2 is less than 10. If it is, it returns “Small”. If not, it checks if the number is less than 20. If it is, it returns “Medium”. If the number is neither less than 10 nor less than 20, it returns “Large”.

Example #3: IF Function with the AND Operator

Suppose you have a list of employees with their sales and performance ratings and want to identify who is eligible for a bonus. The bonus is given to those who have made sales over $10,000 and have a performance rating of 5. You can use the IF function with the AND operator as follows:

=IF(AND(B2>10000, C2=5), “Eligible”, “Not Eligible”)

In this case, B2 contains the sales data, and C2 contains the performance ratings. If both conditions are met, the function will return “Eligible”. If not, it will return “Not Eligible”.

Example #4: IF Function with the OR Operator

Let’s say you have a list of products and their quantities in stock and want to identify which products need reordering. The product needs to be reordered if the quantity in stock is less than 5 or if the product is a “Best Seller”. You can use the IF function with the OR operator as follows:

=IF(OR(B2<5, C2=”Best Seller”), “Reorder”, “Don’t Reorder”)

Here, B2 is the cell containing the quantity in stock, and C2 is the cell containing the product status. If either of the conditions is met, the function will return “Reorder”. If not, it will return “Don’t Reorder”.

IF: Common Mistakes & Problems

When using the IF function in Google Sheets, there are several common mistakes and problems you may encounter:

  • Incorrect Syntax: One of the most common issues is using the wrong syntax. The correct syntax is IF(logical_expression, value_if_true, value_if_false). If you don’t follow this format, Google Sheets can’t execute the function correctly.
  • Logical Expression Errors: The logical expression must be an equation that Google Sheets can evaluate as true or false. Google Sheets will return an error if your logical expression is invalid.
  • Mismatched Parentheses: Each opening parenthesis in your IF function needs a corresponding closing parenthesis. You will get a formula parse error if they are mismatched or missing.
  • Incorrect Data Types: The value_if_true and value_if_false parameters must match the data type your logical expression expects. For example, if your logical expression compares text strings, then value_if_true and value_if_false must also be text strings.
  • Nesting Errors: You can nest IF functions within each other to evaluate multiple conditions. However, Google Sheets allows a maximum of 64 levels of nesting. If you exceed this limit, you will receive an error.

Why Is IF Not Working? Troubleshooting Common Errors

If you are facing issues while using the IF function in Google Sheets, it could be due to several reasons. This section will guide you through some of the most common errors, their causes, and how to fix them.

#VALUE! Error

Cause: This error typically occurs when the logical expression used in the IF function is incorrect. For instance, if you’re comparing a numerical value with a text string, Google Sheets won’t be able to evaluate the condition and will return a #VALUE! error.

Solution: To fix this error, ensure the logical expression is correct. Check the data types of the values you’re comparing. Use functions like TO_TEXT or TO_NUMBER to convert the data into the correct type before comparing it within the IF function.

#NAME? Error

Cause: The #NAME? error usually results from a misspelled function name or a missing parenthesis. Google Sheets can’t recognize the function and thus returns a #NAME? error.

Solution: To resolve this issue, double-check the spelling of your function and ensure that all parentheses are properly closed. Using the built-in function auto-complete feature in Google Sheets can help you avoid spelling errors.

#ERROR! Error

Cause: The #ERROR! error often appears when there’s a problem with the syntax of the IF function. This can be due to missing or extra commas, unmatched parentheses, or incorrect use of function arguments.

Solution: To fix this error, carefully check the syntax of your IF function. Make sure all arguments are correctly placed and separated by commas. Ensure all parentheses are matched. Refer to the correct syntax of the IF function for guidance: IF(logical_expression, value_if_true, value_if_false).

#REF! Error

Cause: The #REF! error usually occurs when a formula refers to a cell that is not valid. This can happen if the cell has been deleted or the formula is trying to reference a cell outside the spreadsheet’s limits.

Solution: To correct this error, check the cell references within your IF function. Ensure all referenced cells exist and are within the valid range of your spreadsheet. Replace any invalid cell references with valid ones.

#DIV/0! Error

Cause: The #DIV/0! error is returned when a formula tries to divide a number by zero, which is mathematically undefined.

Solution: To solve this error, identify and modify the part of your IF function that’s causing a division by zero. You might need to add a condition to your IF function that checks if the denominator is zero before performing the division. If it is, you can return an error message or a specific value instead.

Using IF With Other Google Sheets Functions

Combining the IF function with other Google Sheets functions can give you more flexibility and power in your spreadsheet tasks. It allows you to create more complex conditions and execute more sophisticated operations. Here are a few examples of using IF with other Google Sheets functions:

With SUM

Usage: You can use the SUM function with IF to add up numbers in a range based on a condition.

Example: Suppose you have a list of sales data and want to find out the total sales made by a specific salesperson. You can use SUM combined with IF to do this. Here’s how you can do it:

=SUM(IF(A2:A10=”John”, B2:B10, 0))

In this example, A2:A10 is the range containing the salesperson’s names and B2:B10 is the range containing the sales amount. The formula will add up all the sales amounts where the corresponding salesperson’s name is “John”.

With COUNTIF

Usage: You can use the COUNTIF function with IF to count the number of cells in a range that meet a specific condition.

Example: Suppose you have a list of students and their grades. You want to count the number of students who have a grade of “A”. You can use COUNTIF combined with IF to do this. Here’s how you can do it:

=IF(COUNTIF(B2:B10,”A”)>5, “More than 5 students got an A”, “5 or fewer students got an A”)

In this example, B2:B10 is the range containing the grades. The formula will return “More than 5 students got an A” if the count of “A” grades is more than 5. Otherwise, it will return “5 or fewer students got an A”.

With VLOOKUP

Usage: You can use the VLOOKUP function with IF to look up a value in a table based on a condition.

Example: Suppose you have a table of product data and you want to find the price of a specific product. If the product is not found, you want to return a custom message. You can use VLOOKUP combined with IF to do this. Here’s how you can do it:

=IF(ISNA(VLOOKUP(“Product1”, A2:B10, 2, FALSE)), “Product not found”, VLOOKUP(“Product1”, A2:B10, 2, FALSE))

In this example, “Product1” is the product you’re looking for, A2:B10 is the range of the product table, and 2 is the column index number where the price information is located. The formula will return the price of “Product1” if it’s found in the table. Otherwise, it will return “Product not found”.

For more details on the IF function, check out the official documentation at the Google Docs Editors Help Center.

More Google Sheets Tutorials
More Microsoft Excel Tutorials
Share This Post
Daniel Smith
Daniel Smith
Daniel Smith is automation consultant with a passion for technology, data, AI, and machine learning.

The Spreadsheet Daddy add-on rebrands to Synterrix. Click here to learn more.

X