Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Excel Logic Function Playbook

Sep 15, 2020 • 12 Minute Read

Introduction

In this guide, you will learn how to work with logical functions in Microsoft Excel 2019. There are various logical functions which are present in the Excel 2019 version, as mentioned below:

  • TRUE
  • FALSE
  • OR
  • AND
  • NOT
  • XOR
  • IF
  • IFERROR
  • IFNA
  • IFS
  • SWITCH

The TRUE and FALSE Functions

Use the TRUE and FALSE functions when you want to showcase if a given condition is met or not. For instance, 5 < 3 is a correct condition, and when a TRUE function is used with an IF function (or any other conditional function) it returns a TRUE value. Had the condition been wrong, it would have resulted in the FALSE value.

Notice that the TRUE function is not the same as the TRUE value. The TRUE function doesn't hold any argument inside the round brackets.

The OR Function

A logical OR function follows the given truth table:

Input AInput BInput COutput
0000
0011
0101
0111
1001
1011
1101
1111

In the above table, you can also consider 0 as a FALSE value and 1 as a TRUE value. As you can observe if any input has a TRUE value then the output of the logical OR function is TRUE. However, if all the inputs are FALSE then the output becomes FALSE.

Here's a scenario that will help you implement the logical OR function in Excel. You take five students' attendance who have registered for a workshop. The final attendance is marked only when a student is present on any one of the days. Here's the data:

ABCDE
Student listDay 1Day 2Day 3Attendance
1Student 1TRUEFALSETRUE?
2Student 2TRUETRUETRUE?
3Student 3TRUEFALSETRUE?
4Student 4TRUETRUEFALSE?
5Student 5FALSEFALSEFALSE?

So, to fill the attendance, you use the logical OR formula with this syntax:

      =OR(logical_value1, logical_value2, ... )
    

Put the formula =OR(B1, C1, D1) in cell E1 and then apply it in subsequent rows. This will result in the updated attendance as shown:

ABCDE
Student listDay 1Day 2Day 3Attendance
1Student 1TRUEFALSETRUETRUE
2Student 2TRUETRUETRUETRUE
3Student 3TRUEFALSETRUETRUE
4Student 4TRUETRUEFALSETRUE
5Student 5FALSEFALSEFALSEFALSE

The AND Function

A logical AND function follows the given truth table:

Input AInput BInput COutput
0000
0010
0100
0110
1000
1010
1100
1111

As mentioned in the OR function section, you can also consider 0 as a FALSE value and 1 as a TRUE value. As you can observe if any input has a FALSE value then the output of the logical AND function is FALSE. However, if all the inputs are TRUE then the output becomes TRUE.

The syntax of the logical AND function is given below:

      =AND(logical_value1, logical_value2, ... )
    

To learn how to implement the AND function in Excel, consider the same student attendance scenario but this time assume that if a student is absent even a single day then he/she will be marked absent (FALSE value).

This time, cell E1 will hold the following formula: =AND(B1, C1, D1). This will result in the following attendance sheet where only one student is marked present.

ABCDE
Student listDay 1Day 2Day 3Attendance
1Student 1TRUEFALSETRUEFALSE
2Student 2TRUETRUETRUETRUE
3Student 3TRUEFALSETRUEFALSE
4Student 4TRUETRUEFALSEFALSE
5Student 5FALSEFALSEFALSEFALSE

The NOT Function

The logical NOT function has the following truth table:

InputOutput
TRUEFALSE
FALSETRUE

As you can observe from the table, the NOT function inverts a given logical input.

Consider you have data of people's eating preferences which includes their Veg and Non-Veg type inputs, as shown in the table below. How can you select those people who prefer Non-Veg?

AB
Food PreferenceResult
1Veg?
2Non-Veg?

Use the following syntax to implement the NOT function:

      =NOT(logical_condition)
    

So, you can write a condition to check if peoples’ food preference is Veg and then later pass the result to the NOT function. To achieve this, you can write =NOT(A1="Veg") in the cell B1 which will give you the following result:

AB
Food PreferenceResult
1VegFALSE
2Non-VegTRUE

The XOR Function

A logical XOR function follows the given truth table:

Input AInput BInput COutput
0000
0011
0101
0110
1001
1010
1100
1111

To understand the above table, consider two inputs at a time. If there is the same value in both inputs then the result is FALSE (or 0). Next, use this result of the first two inputs, then take the third input and perform the same action. To illustrate this, take the last row which has 1 for all the inputs. Here, Input A and B has 1 and 1 respectively which gives 0. Now, combine this 0 and Input C (1). As you can observe, this time you have different values; hence, the output is 1.

To illustrate this in Excel, consider an example where a child is presented with three different food items. At one time, she is given a choice between two food items and she can't choose both. Once the choice from the first two is made then the third item is presented for a final choice.

ABCD
CandyIce-creamChocolateResult
1TRUEFALSEFALSE?
2TRUEFALSETRUE?
3FALSEFALSEFALSE?
4TRUETRUETRUE?

The syntax for the logical XOR in Excel is:

      =XOR(logical_value1, logical_value2, ... )
    

To solve the given scenario, we can implement the XOR function starting with =XOR(A1, B1, C1) formula in the cell D1 and stretching it to the subsequent rows. This results in the given table:

ABCD
CandyIce-creamChocolateResult
1TRUEFALSEFALSETRUE
2TRUEFALSETRUEFALSE
3FALSEFALSEFALSEFALSE
4TRUETRUETRUETRUE

The IF Function

The logical IF function checks for a given condition. If the condition holds TRUE, the first argument after the conditional argument is returned or else the second argument after the conditional argument is returned.

The syntax of the IF function in Excel is given below:

      =IF(condition, true_value, false_value)
    

Consider a case where you are provided with the data of students’ marks. You need to mark a student as failed if their total marks are less than, or equal to, 150 out of 500.

AB
Total marksResult
1425?
2125?
3325?
4441?
587?
6222?

This can be achieved by using the logical IF function. You can write the given formula =IF(A1 <= 150, "FAIL", "PASS") in the cell B1 and apply the formula in the subsequent rows to achieve the following result:

AB
Total marksResult
1425PASS
2125FAIL
3325PASS
4441PASS
587FAIL
6222PASS

The IFERROR Function

The logical IFEEROR function is used to catch an error and handle it. If the expression doesn't result in the error then the expression is evaluated, or else the second argument is displayed.

The syntax of the IFERROR function in Excel is given below:

      =IFERROR(expression, response_on_error)
    

Consider an example where you are given two inputs (both numeric) and you need to divide input A by input B. We will try to arrive at a Zero Division Error and, wherever it occurs, we replace the output with value 10. Here's the data to start with:

ABC
Input AInput BOutput
15423?
22145?
37892?
4980?
5451584?
66512?

To solve this problem, we can use the IFERROR function by writing its formula in cell C1 as =IFERROR(A1/B1, 10) which results in the following table:

ABC
Input AInput BOutput
154232.347826087
221450.466666667
37892394.5
498010
54515840.772260274
665125.416666667

The IFNA Function

The logical IFNA function is mostly similar to the IFERROR function except for the error it checks for a #N/A value i.e., a missing value.

Note - A missing value is not similar to a blank value.

The syntax for the IFNA function is given below:

      =IFNA(expression, value_if_NA)
    

Consider a scenario where you have a missing value as well as a blank value in your input data and then implement the IFNA function. For a missing value, you should pass the output value as a NULL value. Here's the data to experiment:

AB
InputOutput
1#N/A?
2 ?
3#N/A?
40?
5584?
612?

You can implement the formula =IFNA(A1, "NULL value") in the cell B1 to get the following output. Now, observe the output for cell B2.

AB
InputOutput
1#N/ANULL value
2 0
3#N/ANULL value
400
5584584
61212

The IFS and SWITCH Functions

The IFS function checks for multiple expressions in one go, as compared to the simple IF function. The syntax is given below:

      =IFS(expression1, value_if_expression1_is_true, expression2, value_if_expression2_is_true, ...)
    

The SWITCH function "evaluates one value (called the expression) against a list of values and returns the result corresponding to the first matching value. If there is no match, an optional default value may be returned," according to Excel's documentation. The syntax is given below:

      =SWITCH(condition, value1, response1, value2, response2, ..., default)
    

These two functions are left for you to tryout on your own!

Conclusion

In this guide, you have learned about the various logical functions available in MS Excel 2019 like TRUE, IF, OR, NOT, etc.