0% found this document useful (0 votes)
31 views

Logical Functions

The document discusses logical functions in Microsoft Excel, including AND, OR, XOR, and NOT. It provides syntax and examples of formulas using each function. Common uses of the AND and OR functions are described, such as using them within IF statements. The document also covers using multiple logical functions together and creating 'between' formulas using AND.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Logical Functions

The document discusses logical functions in Microsoft Excel, including AND, OR, XOR, and NOT. It provides syntax and examples of formulas using each function. Common uses of the AND and OR functions are described, such as using them within IF statements. The document also covers using multiple logical functions together and creating 'between' formulas using AND.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

EXCEL LOGICAL FUNCTIONS

1.0 Introduction
Microsoft Excel provides 4 logical functions to work with the logical values. The functions are
AND, OR, XOR and NOT. You use these functions when you want to carry out more than one
comparison in your formula or test multiple conditions instead of just one. As well as logical
operators, Excel logical functions return either TRUE or FALSE when their arguments are
evaluated.

The following table provides a short summary of what each logical function does to help you
choose the right formula for a specific task.

Function Description Formula Example Formula Description

Returns TRUE
The formula returns TRUE if a
if all of the
value in cell A3 is greater than or
AND arguments =AND(A3>=10, B3<5)
equal to 10, and a value in B3 is
evaluate to
less than 5, FALSE otherwise.
TRUE.

The formula returns TRUE if A3 is


Returns TRUE
greater than or equal to 10 or B3 is
if any argument
OR =OR(A3>=10, B3<5) less than 5, or both conditions are
evaluates to
met. If neither of the conditions it
TRUE.
met, the formula returns FALSE.

The formula returns TRUE if


Returns a either A3 is greater than or equal to
logical 10 or B3 is less than 5. If neither of
XOR =XOR(A3>=10, B3<5)
Exclusive Or of the conditions is met or both
all arguments. conditions are met, the formula
returns FALSE.

Returns the
reversed logical
value of its
argument. I.e. If The formula returns FALSE if a
NOT the argument is =NOT(A3>=10) value in cell A3 is greater than or
FALSE, then equal to 10; TRUE otherwise.
TRUE is
returned and
vice versa.

1
1.1. Using the AND function in Excel
The AND function is the most popular member of the logic functions family. It comes in handy
when you have to test several conditions and make sure that all of them are met. Technically, the
AND function tests the conditions you specify and returns TRUE if all of the conditions evaluate
to TRUE, FALSE otherwise.

The syntax for the Excel AND function is as follows:

AND(logical1, [logical2], …)

Where logical is the condition you want to test that can evaluate to either TRUE or FALSE. The
first condition (logical1) is required, subsequent conditions are optional.

And now, let's look at some formula examples that demonstrate how to use the AND functions in
Excel formulas.

Formula Description

Returns TRUE if A3 contains "Bananas" and B3


=AND(A3="Bananas", B3>C3)
is greater than C3, FALSE otherwise.

Returns TRUE if B3 is greater than 20 and B3 is


=AND(B3>20, B3=C3)
equal to C3, FALSE otherwise.

Returns TRUE if A3 contains "Bananas", B3 is


=AND(A3="Bananas", B3>=30, B3>C3) greater than or equal to 30 and B3 is greater than
C3, FALSE otherwise.

2
1.1.1. Excel AND function - common uses

By itself, the Excel AND function is not very exciting and has narrow usefulness. But in
combination with other Excel functions, AND can significantly extend the capabilities of your
worksheets.

One of the most common uses of the Excel AND function is found in the logical_test argument
of the IF function to test several conditions instead of just one. For example, you can nest any of
the AND functions above inside the IF function and get a result similar to this:

=IF(AND(A3="Bananas", B2>C2), "Good", "Bad")

1.1.2. An Excel formula for the BETWEEN condition

If you need to create a between formula in Excel that picks all values between the given two
values, a common approach is to use the IF function with AND in the logical test.

For example, you have 3 values in columns A, B and C and you want to know if a value in
column A falls between B and C values. To make such a formula, all it takes is the IF function
with nested AND and a couple of comparison operators:

Formula to check if X is between Y and Z, inclusive:

=IF(AND(A3>=B3,A3<=C3),"Yes", "No")

3
Formula to check if X is between Y and Z, not inclusive:

=IF(AND(A3>B3, A3<C3),"Yes", "No")

1.2. Using the OR function in Excel


As well as AND, the Excel OR function is a basic logical function that is used to compare two
values or statements. The difference is that the OR function returns TRUE if at least one if the
arguments evaluates to TRUE, and returns FALSE if all arguments are FALSE. The OR function
is available in all versions of Excel 2016 - 2000.

The syntax of the Excel OR function is very similar to AND:

OR(logical1, [logical2], …)

Where logical is something you want to test that can be either TRUE or FALSE. The first logical
is required, additional conditions (up to 255 in modern Excel versions) are optional.

And now, let's write down a few formulas for you to get a feel how the OR function in Excel
works.

Formula Description

Returns TRUE if A3 contains "Bananas" or


=OR(A3="Bananas", A3="Oranges")
"Oranges", FALSE otherwise.

Returns TRUE if B3 is greater than or equal to 40 or


=OR(B3>=40, C3>=20)
C3 is greater than or equal to 20, FALSE otherwise.

4
Returns TRUE if either B2 or C2 is blank or both,
=OR(B3=" ", C3="")
FALSE otherwise.

As well as Excel AND function, OR is widely used to expand the usefulness of other Excel
functions that perform logical tests, e.g. the IF function. Here are just a couple of examples:

1.2.1. IF function with nested OR

=IF(OR(B3>30, C3>20), "Good", "Bad")

The formula returns "Good" if a number in cell B3 is greater than 30 or the number in C2 is
greater than 20, "Bad" otherwise.

1.2.2. Excel AND / OR functions in one formula

Naturally, nothing prevents you from using both functions, AND & OR, in a single formula if
your business logic requires this. There can be infinite variations of such formulas that boil down
to the following basic patterns:

=AND(OR(Cond1, Cond2), Cond3)

=AND(OR(Cond1, Cond2), OR(Cond3, Cond4)

=OR(AND(Cond1, Cond2), Cond3)

=OR(AND(Cond1,Cond2), AND(Cond3,Cond4))

For example, if you wanted to know what consignments of bananas and oranges are sold out, i.e.
"In stock" number (column B) is equal to the "Sold" number (column C), the following OR/AND
formula could quickly show this to you:

5
=OR(AND(A2="bananas", B2=C2), AND(A2="oranges", B2=C2))

1.3. Using the XOR function in Excel


In Excel 2013, Microsoft introduced the XOR function, which is a logical Exclusive
OR function. This term is definitely familiar to those of you who have some knowledge of any
programming language or computer science in general. For those who don't, the concept of
'Exclusive Or' may be a bit difficult to grasp at first, but hopefully the below explanation
illustrated with formula examples will help.

The syntax of the XOR function is identical to OR's :

XOR(logical1, [logical2],…)

The first logical statement (Logical 1) is required, additional logical values are optional. You can
test up to 254 conditions in one formula, and these can be logical values, arrays, or references
that evaluate to either TRUE or FALSE.

In the simplest version, an XOR formula contains just 2 logical statements and returns:

• TRUE if either argument evaluates to TRUE.


• FALSE if both arguments are TRUE or neither is TRUE.

6
This might be easier to understand from the formula examples:

Formula Result Description

Returns TRUE because the 1st argument is TRUE and the


=XOR(1>0, 2<1) TRUE
2nd argument is FALSE.

=XOR(1<0, 2<1) FALSE Returns FALSE because both arguments are FALSE.

=XOR(1>0, 2>1) FALSE Returns FALSE because both arguments are TRUE.

When more logical statements are added, the XOR function in Excel results in:

• TRUE if an odd number of the arguments evaluate to TRUE;


• FALSE if is the total number of TRUE statements is even, or if all statements are
FALSE.

The screenshot below illustrates the point:

If you are not sure how the Excel XOR function can be applied to a real-life scenario, consider
the following example. Suppose you have a table of contestants and their results for the first 2
games. You want to know which of the payers shall play the 3rd game based on the following
conditions:

• Contestants who won Game 1 and Game 2 advance to the next round automatically and
don't have to play Game 3.
• Contestants who lost both first games are knocked out and don't play Game 3 either.
• Contestants who won either Game 1 or Game 2 shall play Game 3 to determine who goes
into the next round and who doesn't.

7
A simple XOR formula works exactly as we want:

=XOR(B2="Won", C2="Won")

And if you nest this XOR function into the logical test of the IF formula, you will get
even more reasonable results:

=IF(XOR(B2="Won", C2="Won"), "Yes", "No")

8
1.4. Using the NOT function in Excel
The NOT function is one of the simplest Excel functions in terms of syntax:

NOT(logical)

You use the NOT function in Excel to reverse a value of its argument. In other words, if logical
evaluates to FALSE, the NOT function returns TRUE and vice versa. For example, both of the
below formulas return FALSE:

=NOT(TRUE)

=NOT(2*2=4)

Why would one want to get such ridiculous results? In some cases, you might be more interested
to know when a certain condition isn't met than when it is. For example, when reviewing a list of
attire, you may want to exclude some color that does not suit you. I'm not particularly fond of
black, so I go ahead with this formula:

=NOT(C2="black")

As usual, in Microsoft Excel there is more than one way to do something, and you can achieve
the same result by using the Not equal to operator: =C2<>"black".

If you want to test several conditions in a single formula, you can use NOT in conjunctions with
the AND or OR function. For example, if you wanted to exclude black and white colors, the
formula would go like:

=NOT(OR(C2="black", C2="white"))

And if you'd rather not have a black coat, while a black jacket or a back fur coat may be
considered, you should use NOT in combination with the Excel AND function:

9
=NOT(AND(C2="black", B2="coat"))

Another common use of the NOT function in Excel is to reverse the behavior of some other
function. For instance, you can combine NOT and ISBLANK functions to create the
ISNOTBLANK formula that Microsoft Excel lacks.

The formula =ISBLANK(A2) returns TRUE of if the cell A2 is blank. The NOT function can
reverse this result to FALSE: =NOT(ISBLANK(A2))

And then, you can take a step further and create a nested IF statement with the NOT / ISBLANK
functions for a real-life task:

=IF(NOT(ISBLANK(C2)), C2*0.15, “No bonus”)

In simple terms, the formula tells Excel to do the following. If the cell C2 is not empty, multiply
the number in C2 by 0.15, which gives the 15% bonus to each salesman who has made any extra
sales. If C2 is blank, the text "No bonus" appears.

In essence, this is how you use the logical functions in Excel. Of course, these examples have
only scratched the surface of AND, OR, XOR and NOT capabilities. Knowing the basics, you
can now extend your knowledge by tackling your real tasks and writing smart elaborate formulas
for your worksheets.

10

You might also like