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

If the test returns TRUE, you can return a specific result, like "Win" and if the test is FALSE, you can display in the cell "Lost".

Sommaire

## 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

The IF function analyse a test and returns a result in the case the test is TRUE and another one when the test is 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 returns only TRUE or FALSE (or 0 and 1 with this tips and tricks). So to customize your result, you have to write your test in a IF function

## Example: Check the invoices

We want to check if the money received by your 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 :

=B2=C2

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.

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.

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

## 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 with "" (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

=C2-B2

So, we can write or IF function like this now.

=IF(B2<>C2,C2-B2,"")

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. That's what we want 😉😃

## Related articles

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

## 1 comment

## JESUS LOVESBRIAN

11/01/2018 at 11:50 (UTC 1) Link to this comment

Grading of students in class according to their average