Microsoft Tech Community - Latest Blogs - Excel Blog

السبت، 20 أغسطس 2022

Logical Functions

 

Logical Functions


Comparison & TRUE/FALSE

Excel gives you the ability to compare numerical values or strings of text with the following operators:

OperatorDescription
=Equal
<>Does not equal
>Greater than
<Less than
>=Greater than or equal to
<=Less than or equal to

Note: Only = and <> can be used with text.

Example:

=b1>b2

These comparisons return TRUE or FALSE.

1. Test if cell B3 does not equal cell C3.(Hint)
Save Question to Custom Practice Set?

This returns TRUE. If the values did match, it would have returned FALSE.

You might think that TRUE and FALSE are considered text, but actually they are “Boolean” values. Boolean values are very unique. They can actually be used in math formulas. Excel reads TRUE as 1 and FALSE as 0.

2. Multiply the boolean value in cell B3 by cell C3.(Hint)
Save Question to Custom Practice Set?

Unless you are an advanced Excel user or have a programming background, you will probably not make use of this property of TRUE/FALSE, but we've included it for completeness.

You can also compare strings of text. When comparing strings of text, the “Case” (upper or lower) does not matter. “String” will equal “string”.This might seem obvious, but other Text Functions are case dependent.

if-function-syntax

3. Test if cell B3 equals C3.
(Hint)
Save Question to Custom Practice Set?

Logical Functions

Logical Functions use the TRUE/FALSE (Boolean) logic to evaluate criteria and allow you to do one thing if TRUE or another if FALSE.

IF Function

The most common logical function is the IF Function. The IF function tests if a condition is TRUE or FALSE, does one thing if TRUE, or another if FALSE.

=if(condition to test, do if TRUE, do if FALSE)

Ex:

=if(b1 = “AutomateExcel”, c1+c2,”error”)

if-function-syntax

4. Test if cell B3 > C3. If TRUE output “warning”. If false output “” (“” will return a blank string of text)
(Hint)
Save Question to Custom Practice Set?

if-function-syntax

5. Test if cell c4 equals “stop”. If TRUE, set equal to d3. If FALSE, add a4 and b4.
(Hint)
Save Question to Custom Practice Set?

Nested IF Functions

You can actually use multiple functions within a single cell formula. When one function is placed inside another function, it is called “nesting”:

=if(b2>b3,if(b2>b4,”b2 is max”,”b4 is max”),”b3 is max”)

Be careful with nested functions! The more complicated your formulas, the harder they are to review, and the greater the chance for errors. If you need to create complicated formulas, think about breaking them into multiple cells.

In the next section we will introduce you to other “helper” functions that are often nested inside an IF Function.

AND, OR, and XOR Functions

The AND, OR, and XOR Functions perform logical tests and return TRUE or FALSE.

FunctionDescription
ANDTests if ALL conditions are met
ORTests if ANY conditions are met
XORTests if ONLY ONE condition is met

The syntax for all of these functions are the same: Each condition should be separated by a comma.

=and(a1>a2,a1>a3,a1>a4)

or-function-syntax

6. Test if cell C3 or C4 is equal to “warning”.
(Hint)
Save Question to Custom Practice Set?

These functions return either TRUE or FALSE and are often used within IF Functions.

if-function-syntax

7. Nesting an AND Function within a IF Function, Test if cell C3 and C4 both equal “warning”. If so, output “Uh oh!”, if not output a blank string.
(Hint)
Save Question to Custom Practice Set?

xor-function-syntax

8. Test if only one of C3 or C4 equals “warning”.
(Hint)
Save Question to Custom Practice Set?

IS and IFERROR Functions

You can perform specific logical tests using the IS Functions:

FunctionDescription
IsBlankChecks if a cell is blank
IsErrChecks if a cell is an error, excluding #N/A
IsErrorChecks if a cell is an error
IsEvenChecks if a cell is even
IsLogicalChecks if a cell is a logical value
IsNAChecks if a cell is #N/A
IsNonTextChecks if a cell is not text
IsNumberChecks if a cell is a number
IsOddChecks if a cell is odd
IsRefChecks if a cell is a reference
IsTextChecks if a cell is text

isnumber-function-syntax

9. Test if cell B3 is a number.
(Hint)
Save Question to Custom Practice Set?

istext-function-syntax

10. Test if cell B3 is text.
(Hint)
Save Question to Custom Practice Set?

isblank-function-syntax

11. Test if cell B3 is blank.
(Hint)
Save Question to Custom Practice Set?

IFERROR Function.

The IFERROR Function tests if a calculation results in an error. If not, it returns the original result, if it does result in an error then it returns another value. Example:

IFERROR(VLOOKUP(a1,data,5,false),””)

This example is using a vlookup (we will learn about this function later) to return a value. IF the lookup value can not be found, it returns 'blank' instead of an error.

We recommend using the IFERROR Function to make your spreadsheets look more professional. If you show your manager or a client a spreadsheet filled with errors (even if they are valid), they will be concerned. Instead use the IFERROR to handle valid errors!

There are two particularly common cases when you should use an IFERROR:

  • When doing any kind of lookup where a lookup value may (correctly) not be found.
  • When dividing numbers where the denominator could equal 0.

iferror-function-syntax

12. Calculate the percentage of units sold in row 4. Use the IFERROR Function to return 0 instead of an error value if the denominator is 0.
(Hint)

ليست هناك تعليقات:

إرسال تعليق