What IF? Microsoft Excel’s popular IF function explained

True or False? Excel does so much more than just storing data.

Wouldn’t it be nice if there was a function in Excel that could help you test specific conditions within your data?

Oh wait, there is! 

One of the biggest misconceptions people have about Excel is that spreadsheets are just a place for storing data. But that’s not true – they can do so much more! 

Excel Ace has been around for 15 years now, and there’s a reason it’s had such longevity (and that I’ve never once found myself bored of spreadsheets). With its vast range of functions and formulas, there’s an almost limitless amount of things you can do with Excel

I love helping people discover the answers to their problems using Excel, and one of the most popular functions that can be used to do this is the IF function.

The IF Function allows you to make logical comparisons of your data based on specific conditions. It works by comparing the data you enter with specific criteria, returning the relevant value depending on whether the result was true (yes) or false (no) for that data value. 

You can modify the values that are returned, either as a value or text, that will signify whether the data met the conditions in the formula you entered. There are a number of ways you can formulate an IF function, and I’ll break these down for you in this article. 

I’ll also take you through everything you need to know about the IF function and teach you how to use it effectively to streamline your data-processing tasks.

The wonderful thing about the IF function is that it can truly be tailored to fit your needs.

Sounds good? Then keep reading to find out more.

Understanding the IF Function

Here’s the ‘techy bit (but don’t worry, I’ll explain it more simply too)’:

The IF function is a logical function in Excel that evaluates a given condition and returns one value if the condition is met (TRUE) and another value if the condition is not met (FALSE). 

Its basic syntax is as follows:

=IF(logical_test, value_if_true, value_if_false)

The “logical_test” is the condition that Excel evaluates (the element that you want to put to the test). 

If the logical_test is true, the function returns “value_if_true,” and if the logical_test is false, it returns “value_if_false.”

I appreciate that this might not be very clear to wrap your head around, so let’s put that syntax into some better context. Take a look at a simple IF function example below.

A simple IF function example

Suppose you have a list of exam scores for people who have taken your training programme in column A of your sheet, and you want to categorise the scores as a “Pass” if they are greater than or equal to 60 and a “Fail” otherwise for those that are lower.

You can use the IF function to automatically categorise them based on this scoring criteria. This would look like:

=IF(A2 >= 60, “Pass”, “Fail”)

This formula checks if the value in cell A2 is greater than or equal to 60. If true, it returns “Pass” otherwise, it returns “Fail.”

Bonus Tip: If you want Excel to check multiple rows of data at once, simply copy this formula across the full range of rows. To do this easily, hover your cursor over the lower right corner of your cell until it turns to a thin cross, click, and drag to cover the desired cell range.

Nested IF Functions

Excel allows you to ‘nest’ IF functions, meaning you can have multiple conditions and results.

Let’s take a more complex scenario where you want to categorise exam scores as “Excellent,” “Good,” “Average,” or “Fail” based on their specific score ranges. Let’s say you define each of the scores by the following ranges: 

  • Excellent – Equal to or greater than 90
  • Good – Equal to or greater than 80
  • Average – Equal to or greater than 70
  • Fail – Any score not covered by the above parameters(i.e less than 70)

The syntax for this would therefore look like:

=IF(A2 >= 90, “Excellent”, IF(A2 >= 80, “Good”, IF(A2 >= 70, “Average”, “Fail”)))

In this example, the nested IF function checks the score in cell A2 against different thresholds and assigns them with the appropriate category. 

So if the score is 95, the function will return “Excellent”; if the score is 85, it will return “Good,” and so on.

This is a great way to save heaps of time in manually checking and allocating your data to multiple categories. 

IF Function with Logical Operators

The IF function can also incorporate logical operators such as AND and OR to evaluate multiple conditions. 

For instance, suppose you want to categorise trainees based on their exam scores AND attendance to training sessions.

If a trainee scored above 80 and attended more than 90% of classes, they receive a “High Performer” tag; otherwise, they are classified as “Regular Performer”. 

Here’s what the formula will look like with these conditions: 

=IF(AND(A2 > 80, B2 > 0.9), “High Performer”, “Regular Performer”)

In this formula, the AND function checks both conditions: whether the score in cell A2 is above 80 and whether the attendance percentage in cell B2 is greater than 90%. 

If both conditions are true, the student is labelled as a “High Performer”, if they are not, then they will receive the label of “Regular Performer”.

With AND function, there can be as many conditions as required, but it is essential that ALL criteria return TRUE, for the overall result to be TRUE. If only one if the Conditions return FALSE, then the overall result will always be FALSE. 

In contrast, we can also use the OR function. This works in exactly the same way as AND, but simply requires just ONE of the conditions to return TRUE for the overall result to also be TRUE.

IF Function with Error Handling

You can use the IF function to handle errors or display custom messages when certain conditions are not met. 

This is really helpful when you need a spreadsheet to clearly flag when an error is occurring. It means you’ll have a prompt and reminder to follow up on it, so it won’t be missed.

So let’s say you have a division operation in cell A2, and you want to display “Error” if the divisor (cell B2) is zero. Your formula would need to look like this: 

=IF(B2 = 0, “Error: Cannot divide by zero”, A2/B2)

This formula checks if B2 is zero. If it’s true, it returns the custom error message “Error: Cannot divide by zero”; otherwise, it performs the division operation for you.

IF Function with Text and Blank Cells

The IF function is not limited to numeric comparisons; it works with text values as well! 

Suppose you have a list of products, and you want to categorise them as “In Stock” if the quantity (cell B2) is greater than zero, and “Out of Stock” if the cell is blank. Try this:

=IF(B2 > 0, “In Stock”, “Out of Stock”)

In this formula, if the quantity is greater than zero, the cell will display “In Stock”; otherwise, if the cell is blank, it will show “Out of Stock.”

IF Function with Date Comparisons

The IF function is incredibly useful for handling date-based data too. This can be especially helpful when you’re managing project deadlines (I use it all the time to help me stay on track with my workload!)

Say you want to categorise your deadlines as “On Time” if the deadline (cell C2) is on or after the current date, and “Delayed” if the deadline has passed. You’d input your formula as follows: 

=IF(C2 >= TODAY(), “On Time”, “Delayed”)

In this formula, the TODAY() function returns the current date, and the IF function checks if the deadline is on or after today. If true, it returns “On Time”; otherwise, it returns “Delayed.”

Summary

Excel’s IF function is an ACE tool for empowering you to work with data in a more intelligent and responsive way. 

From making data-driven decisions to performing complex calculations, and handling errors in your spreadsheets efficiently, the IF function is super helpful to have up your sleeve when analysing data. 

By understanding the syntax and incorporating logical operators, you can tailor the IF function to meet various scenarios that match the needs of your data analysis and reporting tasks. 

Experiment with different conditions and nested functions to unlock the full potential of the IF function in Excel. If you need any help with doing this, you can reach out to me here.

Incorporating the IF function into your Excel spreadsheets is going to be one of the best decisions you make (I promise), and you’ll be amazed at how it simplifies and enhances your data processing capabilities.

Even the most experienced Excel user can face a stumbling block from time to time, that’s why we offer a simple and easy-to-access support package. To book a support package, click here.

Share This Article

More To Explore

Join the Excel Ace community!
Get FREE Excel tips, guides, and industry insights delivered straight to your inbox. Sign up for our newsletter today!
Please enable JavaScript in your browser to complete this form.
Name