You are on page 1of 5

Data and Computing Skills

Week 4.1.
Logical Functions
Logical operators
A logical operator is used in Excel to compare two values. Logical operators are sometimes called
Boolean operators because the result of the comparison in any given case can only be either
TRUE or FALSE.

• Boolean logic is the formal description for the idea of TRUE and FALSE in this context.
• Boolean logic is rooted in the idea of binary logic of 1s and 0s. In that sense, TRUE is
synonymous to 1 while FALSE equates to 0.
Six logical operators are available in Excel. The following table explains what each of them does
and illustrates the theory with formula examples.

Condition Operator Formula Description


Example
Equal to = =A1=B1 The formula returns TRUE if a value in cell A1 is
equal to the values in cell B1; FALSE otherwise.
Not equal to <> =A1<>B1 The formula returns TRUE if a value in cell A1 is
not equal to the value in cell B1; FALSE otherwise.
Greater than > =A1>B1 The formula returns TRUE if a value in cell A1 is
greater than a value in cell B1; otherwise it returns
FALSE.
Less than < =A1<B1 The formula returns TRUE if a value in cell A1 is
less than in cell B1; FALSE otherwise.
Greater than or >= =A1>=B1 The formula returns TRUE if a value in cell A1 is
equal to greater than or equal to the values in cell B1;
FALSE otherwise.
Less than or <= =A1<=B1 The formula returns TRUE if a value in cell A1 is
equal to less than or equal to the values in cell B1; FALSE
otherwise.

1|P a g e
Data and Computing Skills

Equal Sign (=) to Compare Two Values


The Equal to logical operator (=) can be used to compare all data types - numbers, dates, text
values, Booleans, as well as the results returned by other Excel formulas. For example:

Returns TRUE if the values in cells A1 and B1 are the same, FALSE
=A1=B1
otherwise.
=A1="oranges" Returns TRUE if cells A1 contain the word "oranges", FALSE otherwise.
Returns TRUE if cells A1 contain the Boolean value TRUE, otherwise it
=A1=TRUE
returns FALSE.
Returns TRUE if a number in cell A1 is equal to the quotient of the
=A1=(B1/2)
division of B1 by 2, FALSE otherwise.

Using the "Equal to" operator with text values

Using Excel's Equal to operator with text values does not require any extra twists. The only thing
you should keep in mind is that the Equal to logical operator in Excel is case-insensitive,
meaning that case differences are ignored when comparing text values.

For example, if cell A1 contains the word "oranges" and cell B1 contains "Oranges", the
formula =A1=B1 will return TRUE.

If you want to compare text values taking in to account their case differences, you should use the
EXACT function instead of the Equal to operator. The syntax of the EXACT function is as simple
as:

EXACT(text1, text2)

Where text 1 and text2 are the values you want to compare. If the values are exactly the same,
including case, Excel returns TRUE; otherwise, it returns FALSE. You can also use the EXACT
function in IF formulas when you need a case-sensitive comparison of text values, as shown in
the below screenshot:

2|P a g e
Data and Computing Skills

Comparing Boolean values and numbers

There is a widespread opinion that in Microsoft Excel the Boolean value of TRUE always equates
to 1 and FALSE to 0. However, this is only partially true, and the key word here is "always" or
more precisely "not always" !

When writing an 'equal to' logical expression that compares a Boolean value and a number, you
need to specifically point out for Excel that a non-numeric Boolean value should be treated as a
number. You can do this by adding the double minus sign in front of a Boolean value or a cell
reference, e. g. =A2=--TRUE or =A2=--B2.

The 1st minus sign, which is technically called the unary operator, coerces TRUE/FALSE to -1/0,
respectively, and the second unary negates the values turning them into +1 and 0. This will
probably be easier to understand looking at the following screenshot:

Note. You should add the double unary operator before a Boolean when using other logical
operators such as not equal to, greater than or less than to correctly compare a numeric and
Boolean values.

Let’s look at more examples that the Equal to logical operator (=) can be used to compare
different data types:

3|P a g e
Data and Computing Skills

However, as you can see, even though some of the compared cells appeared to be the same, the
outcome was FALSE. The primary cause for this is the variety of format variances. For example,
A9 and B9 both appear as 1/1/2001, however upon closer observation, it is clear that A9 is text
rather than a date.
The next figure shows a more detailed version of compared cells.

"Not equal to" logical operator


You use Excel's Not equal to operator (<>) when you want to make sure that a cell's value is not
equal to a specified value. The use of the Not equal to operator is very similar to the use
of Equal to that we discussed a moment ago.
The results returned by the Not equal to operator are analogous to the results produced by the
Excel NOT function that reverses the value of its argument. The following table provides a few
formula examples.

Not equal to operator Description


=A1<>B1 Returns TRUE if the values in cells A1 and B1 are not
the same, FALSE otherwise.
=A1<>"oranges" Returns TRUE if cell A1 contains any value other than
"oranges", FALSE if it contains "oranges" or "ORANGES"
or "Oranges", etc.
=A1<>TRUE Returns TRUE if cell A1 contains any value other than
TRUE, FALSE otherwise.
=A1<>(B1/2) Returns TRUE if a number in cell A1 is not equal to the
quotient of the division of B1 by 2, FALSE otherwise.

4|P a g e
Data and Computing Skills

=A1<>DATEVALUE("12/1/2014" Returns TRUE if A1 contains any value other than the


) date of 1-Dec-2014, regardless of the date format,
FALSE otherwise.

Greater than, less than, greater than or equal to, less than or equal to

You use these logical operators in Excel to check how one number compares to another.
Microsoft Excel provides 4 comparison operates whose names are self-explanatory:

• Greater than (>)


• Greater than or equal to (>=)
• Less than (<)
• Less than or equal to (<=)

Most often, Excel comparison operators are used with numbers, date and time values. For
example:

=A1>20 Returns TRUE if a number in cell A1 is greater than 20,


FALSE otherwise.
=A1>=(B1/2) Returns TRUE if a number in cell A1 is greater than or
equal to the quotient of the division of B1 by 2, FALSE
otherwise.
=A1<DATEVALUE("12/1/2014") Returns TRUE if a date in cell A1 is less than 1-Dec-
2014, FALSE otherwise.
=A1<=SUM(B1:D1) Returns TRUE if a number in cell A1 is less than or equal
to the sum of values in cells B1:D1, FALSE otherwise.

5|P a g e

You might also like