Logical Functions-If and nested if

Today, let’s have a look at logical functions: If and Nested IF

IF Function in Excel

One of the most important functions in MS-Excel is the IF Statement.

It evaluates a certain condition and based on the logical comparison made, if the result of the comparison comes to be true then a particular statement is executed. And if it is false then you can either return the default “false” or nest another if statement to be more precise with your comparison.

Default Syntax of IF Statement in Excel:

=IF ( CONDITION , VALUE_IF_TRUE , VALUE_IF_FALSE )

Now from the above syntax it is clear that the if statement takes 3 arguments.

The last 2 arguments are optional by the way. If the last 2 arguments are not explicitly mentioned the if function will return TRUE or FALSE as the result of the comparison.

The first argument takes the condition to be evaluated. If the condition is true then it executes the 2nd argument, if no argument is passed then returns TRUE or if the condition is false then the 3rd argument’s value is returned. If no argument is given, default valueFALSE” will be returned.

When using the IF function to compare values, you can use the following logical operators:

  • = (equal to)
  • > (greater than)
  • >= (greater than or equal to)
  • < (less than)
  • <= (less than or equal to)
  • <> (not equal to)

Let us see a practical example to understand this:

  • Click on the desired cell and inside the formula bar write your if function as shown below:

In the formula bar you can see the formula i.e. if B2<B1, then return “B1 is Greater”.

Notice we don’t have the 3rd argument for else. In this case if the condition is FALSE it will return “FALSE” as the result.

See for yourself,

You can customize the formula as per your need. Just keep the syntax in mind.

Nested IF statements

One can also nest another if statement inside an IF statement. To have multiple conditions for validation of input data, nested if statements play a very important role.

First let us try a simple IF statement to the following data to determine whether a student passed or failed.

We have applied a simple if formula which evaluates the mark. If the marks is less than 40 then FAIL will be returned else PASS will be returned.

Formula applied is: =IF(B2<40,”FAIL”,”PASS”)

Now if we want to process some advanced conditional statements, for e.g. if we want to assign individual grades according to marks range or just return distinction grades if anyone scores above 90 along with the PASS result, we can use nested IF functions.

Now apply the below formula and observe the results.

=IF(B2<40,”FAIL”,IF(B2>90,”PASS WITH DISTINCTION”,”PASS”))

Now we have an extra condition along with the pass condition i.e. the Pass with Distinction.

And our Nested IF function seems to do the task very well. In this way you can nest some more if functions to produce grades for every individual score.

Try for yourself, nesting the if functions to get your personalised result. We have demonstrated some common use cases. You can give as many as nested ifs inside a single if function, if it is required. Also, you can customize the if function according to your preference. Logical functions: If and Nested IF can be used based on your purpose

Hope you have found this article to be informative. Keep Learning! Peace.

Leave a Comment

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