MS Excel - Logical Functions in Microsoft Excel: IF, IFS, IFERROR and IFNA

Logical functions in Microsoft Excel are used to make decisions based on conditions. They allow Excel to examine values, compare data, and return an appropriate result depending on whether a condition is true or false.

1. IF Function

The IF function is one of the most commonly used logical functions in Excel. It checks whether a specified condition is true or false and returns one result for TRUE and another result for FALSE.

Syntax

=IF(logical_test, value_if_true, value_if_false)

The arguments are:

  • logical_test: The condition that Excel needs to check.

  • value_if_true: The result displayed when the condition is TRUE.

  • value_if_false: The result displayed when the condition is FALSE.

Example

Suppose cell A2 contains a student's marks.

=IF(A2>=40,"Pass","Fail")

If A2 contains 75, Excel displays:

Pass

If A2 contains 25, Excel displays:

Fail

The formula checks whether the marks are greater than or equal to 40. If the condition is satisfied, it returns "Pass"; otherwise, it returns "Fail".

Comparison Operators Used with IF

IF can use different comparison operators to evaluate data.

Operator Meaning Example
= Equal to A2=50
> Greater than A2>50
< Less than A2<50
>= Greater than or equal to A2>=50
<= Less than or equal to A2<=50
<> Not equal to A2<>50

For example:

=IF(B2>50000,"High Salary","Low Salary")

This formula checks whether the value in B2 is greater than 50,000.

IF with Text Values

The IF function can also compare text.

For example:

=IF(C2="Yes","Approved","Rejected")

If C2 contains "Yes", the result is "Approved". If it contains anything else, the result is "Rejected".

This can be useful for employee records, survey forms, application processing, attendance sheets, and approval lists.

IF with Calculations

IF can also perform calculations depending on a condition.

For example:

=IF(A2>=100,A2*10%,0)

If A2 is 100 or more, Excel calculates 10% of A2. Otherwise, it returns 0.

This can be useful for calculating commissions, discounts, bonuses, incentives, and other conditional amounts.


2. IFS Function

The IFS function is useful when a worksheet contains multiple conditions and different results are required for each condition.

Instead of creating several nested IF functions, IFS allows multiple conditions to be placed in one formula.

Syntax

=IFS(condition1,result1,condition2,result2,condition3,result3)

Excel evaluates the conditions from left to right and returns the result associated with the first condition that is TRUE.

Example: Student Grades

Suppose A2 contains a student's marks.

=IFS(A2>=90,"A+",A2>=80,"A",A2>=70,"B",A2>=60,"C",A2>=40,"D",A2<40,"Fail")

If A2 contains 85, Excel evaluates the conditions in sequence:

  • 85 >= 90: FALSE

  • 85 >= 80: TRUE

Therefore, Excel returns:

A

Why the Order Matters

The order of conditions in an IFS formula is important.

Consider:

=IFS(A2>=40,"Pass",A2>=80,"Excellent")

If A2 contains 90, the first condition, A2>=40, is already TRUE. Excel therefore returns "Pass" and does not proceed to the second condition.

A better arrangement would be:

=IFS(A2>=80,"Excellent",A2>=40,"Pass",A2<40,"Fail")

Now higher values are checked first.


3. IFERROR Function

The IFERROR function is used to handle errors produced by Excel formulas.

For example, dividing a number by zero produces a #DIV/0! error.

Instead of allowing the error to appear, IFERROR can display a meaningful message.

Syntax

=IFERROR(value,value_if_error)

Example

=IFERROR(A2/B2,"Invalid Calculation")

If B2 contains a valid number, Excel performs the division normally.

If B2 contains zero and the calculation generates an error, Excel displays:

Invalid Calculation

Another example is:

=IFERROR(A2/B2,0)

Here, Excel displays 0 if the calculation produces an error.

IFERROR can be particularly useful when working with large datasets where errors need to be handled automatically.


4. IFNA Function

The IFNA function is designed specifically to handle the #N/A error.

The #N/A error commonly occurs when a lookup formula cannot find the requested value.

Syntax

=IFNA(value,value_if_na)

For example:

=IFNA(VLOOKUP(E2,A2:B20,2,FALSE),"Not Found")

If the VLOOKUP finds the requested value, Excel returns the corresponding result.

If the lookup cannot find the value and produces #N/A, Excel displays:

Not Found

This makes lookup worksheets easier to understand and prevents users from seeing unnecessary error messages.


5. Difference Between IFERROR and IFNA

Although both functions are used for error handling, they have different purposes.

Function Purpose
IFERROR Handles various Excel errors
IFNA Handles specifically the #N/A error

For example:

=IFERROR(A2/B2,"Error")

can handle errors such as division errors and other formula errors.

Whereas:

=IFNA(VLOOKUP(E2,A2:B20,2,FALSE),"Not Found")

specifically handles the #N/A result from the lookup.

Using IFNA can therefore be preferable when you want to distinguish a missing lookup value from other types of formula errors.


6. Combining IF with AND

IF can be combined with other logical functions to evaluate more than one condition.

For example, suppose a student must score at least 40 marks in both theory and practical examinations.

If theory marks are in A2 and practical marks are in B2:

=IF(AND(A2>=40,B2>=40),"Pass","Fail")

The student receives "Pass" only when both conditions are TRUE.

If either subject has marks below 40, Excel returns "Fail".


7. Combining IF with OR

OR is useful when at least one of several conditions needs to be satisfied.

For example:

=IF(OR(A2="Yes",B2="Yes"),"Eligible","Not Eligible")

If either A2 or B2 contains "Yes", Excel returns "Eligible".

This can be useful when eligibility can be achieved through more than one condition.


8. Practical Example: Employee Performance

Consider an employee performance worksheet:

Employee Performance Score Result
Employee A 92 Excellent
Employee B 78 Good
Employee C 61 Average
Employee D 35 Needs Improvement

An IFS formula could be:

=IFS(B2>=90,"Excellent",B2>=75,"Good",B2>=50,"Average",B2<50,"Needs Improvement")

Excel automatically assigns the appropriate category based on the employee's score.


9. Practical Example: Sales Commission

Suppose a salesperson's sales amount is stored in B2.

A simple IF formula can determine whether the salesperson achieved the target:

=IF(B2>=100000,"Target Achieved","Target Not Achieved")

A more detailed IFS formula could categorize performance:

=IFS(B2>=200000,"Outstanding",B2>=150000,"Excellent",B2>=100000,"Good",B2<100000,"Below Target")

This allows a business to automatically classify sales performance without manually checking every value.


10. Practical Example: Attendance

Suppose an employee's attendance percentage is stored in B2.

=IF(B2>=75,"Eligible","Not Eligible")

If the attendance is 80%, the result is "Eligible".

If the attendance is 65%, the result is "Not Eligible".

For multiple attendance categories:

=IFS(B2>=90,"Excellent",B2>=75,"Good",B2>=60,"Average",B2<60,"Poor")

11. Advantages of Logical Functions

Logical functions provide several important benefits:

  1. They reduce manual decision-making.

  2. They automate repetitive calculations.

  3. They make large worksheets easier to manage.

  4. They can classify data automatically.

  5. They can display meaningful messages instead of raw values or errors.

  6. They can be combined with other Excel functions.

  7. They are useful for financial, educational, business, sales, attendance, and administrative worksheets.

  8. They help create dynamic reports in which results change automatically when source data changes.

Conclusion

Logical functions allow Excel to behave like a decision-making tool rather than simply a calculator. The IF function is useful for simple TRUE/FALSE decisions, while IFS is suitable when several conditions must be evaluated. IFERROR helps manage formula errors, and IFNA provides targeted handling for #N/A errors.

By combining these functions with other Excel functions such as AND and OR, users can create powerful formulas that automatically evaluate information, categorize records, calculate conditional results, and handle unexpected data conditions.