Function IF

The IF function is used to return the result of a test.

If the test returns TRUE, you can return a specific result and if the test is FALSE, you return another result.

The IF function

The IF function is build with 3 parameters

  • The test
  • The result if the test is TRUE
  • The result if the test is FALSE


=IF(test,if test is TUE,if test is FALSE)

 The IF function compares data and returns 2 values (AND ONLY 2) : TRUE or FALSE

Logical Test

The first parameter of the IF function is a logical test. A logical test compares 2 data. You can have these possibilities:


But a logical test return TRUE or FALSE (or 0 and 1 with this trick). So to customize the result, you insert your logical test in a IF function

Example: Check the invoices

We want to check if the money received by our company is the same as the value of the invoices.

Everything looks correct here. But let's have a closer look 🧐. Let's make a test to check if the amount is the same for each rows.

The test

The test is very simple. We just have to compare if the value in column B equal the amount in column C. The test is :


And when you copy this test to the others cells you have this result.

  • When the test is TRUE, it's because the amount is the same in both cells
  • When the test is FALSE, the amount is not equal

Customize the result with a text

We can customized the result of the test with the function IF

  • First parameter, the same test
  • Second parameter, the word "OK"
  • Third result, the word "Wrong amount"

=IF(B2=C2,"OK","Wrong amount")

Optional: Reverse the test

If you prefer to test if the amount between the 2 cells is different, you write your formula like this

=IF(B2<>C2,"Wrong amount","OK")

The result is obviously the same 😉

Why the function returns FALSE?

If you write your function without the third parameter, there is no error

=IF(B2<>C2,"Wrong amount")

But when the test is FALSE, the IF function doesn't know what to return because the third parameter is missing. So in that case, the function return the result of the test.

How to return a result "empty"?

If you don't want to return a result with the IF function, you must fill the third parameter. And the third parameter is a string empty with the code "" (2 double quotes without space between)

=IF(B2<>C2,"Wrong amount","")

Return the result of a formula

Of course, return "Wrong amount" is not what we expect. We prefer to display the difference between the amount received and the amount of the invoice

The formula to returns the difference it's this simple function


So, apply to the IF function, we can write


NOW it's easy to analyze the result. In column D, we have the difference only for the case when the 2 values are not equal.

As you can see, the IF function is very easy to use 😉😃

Related articles

Have a look at these other articles that could help you in your work

Permanent link to this article: https://www.excel-exercise.com/if/

1 comment


    Grading of students in class according to their average

Leave a Reply

Your email address will not be published. Required fields are marked *