Logical functions - worksheet


Logical


All logical functions evaluate the existence of a Boolean value TRUE or FALSE value, and comprise of a logical_test based on a comparison operator.


Comparison operators


Excel comparison operators Description
= equals (eq) Returns TRUE if Value1 is equal to Value2. eg. Value1=Value2
< less than (lt) Returns TRUE if Value1 is less than Value2. eg. Value1<Value2
> greater than (gt) Returns TRUE if Value1 is greater than Value2. eg. Value1>Value2
<= less than or equals (lte) Returns TRUE if Value1 is less than or equal to Value2. eg. Value1<=Value2
>= greater than or equals (gte) Returns TRUE if Value1 is greater than or equal to Value2. eg. Value1>=Value2
<> not equal (ne) Returns TRUE if Value1 is not equal to Value2. eg. Value1<>Value2

Logical functions


Logical functions are grouped under the Logical category in the Excel function library, and the Insert Function dialog box.


Excel logical functions Description
IF Returns one value if the logical test is TRUE, and another value if the logical test is FALSE
AND Returns TRUE if all arguments return TRUE
OR Returns TRUE if any argument returns TRUE
XOR [eXclusive OR; New in Excel 2013] Returns the logical Exclusive Or of all arguments
TRUE Returns the logical value TRUE
FALSE Returns the logical value FALSE
NOT Returns the reverse of its logical argument
IFERROR Returns the value you specify if a formula evaluates to an error; otherwise, returns the result of the formula
IFNA Returns the logical TRUE if value refers to a #N/A error, else it returns FALSE

Examples


IF function


Example: Suppose that the vector named \(Vector\) contains the series \(\{1,2,...9,10\}\) with count of 10 and average value of 5.5. We will now use a series of logical tests to determine if the values 3, and 7 are less than the average, 5.5.



The IF function has optional arguments, but is most commonly used with three arguments.





Nested IF functions


A example - a university handbook describes the marks and grades relationship as shown in figure 1.


xlf-marks-grades-range
Fig 1: Marks grades from a university handbook. Students are awarded a final grade (column 2) based on the marks achieved (column 1)

Mapping marks to grades, from figure 1, using the worksheet IF function.


AND function w/ the TRUE function and FALSE function



OR function

  1. =OR(TRUE(),TRUE(),TRUE()) returns a logical TRUE
  2. =OR(TRUE(),TRUE(),FALSE()) returns a logical TRUE
  3. =OR(FALSE(),FALSE(),FALSE()) returns a logical FALSE
  1. =OR(TRUE(),TRUE()) returns a logical TRUE
  2. =OR(TRUE(),FALSE()) returns a logical TRUE
  3. =OR(FALSE(),FALSE()) returns a logical FALSE

Logically, an OR function should return TRUE when one OR the other of two functions is TRUE. In Excel, this functionality was introduced with the XOR (Exclusive Or) function. This is shown by comparing points 1 to 3 (above) using OR, to points 4 to 6 (below) using XOR.


XOR function

  1. =XOR(TRUE(),TRUE()) returns a logical FALSE
  2. =XOR(TRUE(),FALSE()) returns a logical TRUE
  3. =XOR(FALSE(),FALSE()) returns a logical FALSE

Comparison AND, OR, and XOR


Fig 3: xlf Online: comparison of logical functions AND, OR and XOR AND returns TRUE if all are TRUE OR returns TRUE if at least one is TRUE XOR returns TRUE if either one is TRUE (pair-wise) Note: the formula in cell L9 is: =IF(ISFORMULA(H9),ADDRESS(ROW(H9),COLUMN(H9),4)&": "&FORMULATEXT(H9),ADDRESS(ROW(H9),COLUMN(H9),4)&": "&IF(NOT(ISBLANK(H9)),OneLeft,""))

NOT function


The NOT function is useful when it is easier to write a particular logical test, then reverse the answer. An example is an advanced filter criteria for data filtering.


  1. =NOT(TRUE()) returns a logical FALSE
  2. =NOT("up"="down") returns a logical TRUE