You are on page 1of 8

ECH 12: IF statements

Book: Microsoft Excel 2016 Data Analysis and Business Modeling


IF statement

 Syntax: IF(logical_test, value_if_true, value_if_false)


 Logical_test: anything that generates a Boolean value.
 E.g., comparison, function that generates a Boolean value, etc.
 Value_if_true: any value (number, string, date/time, etc.) to
print when the logical_test evaluates to TRUE.
 Examples
 If(a1> 20, “Good job”, “Do it again”)

Dr. K. Chen, 2015 2


AND(), OR() and Truth Tables

 Syntax: and(logical_test1, logical_test2, …, logical_testn)


 Syntax: or(logical_test1, logical_test2, …, logical_testn)
 Examples:
 And(a1>=10, a1<=20)  10 ≤ a1 ≤ 20
 If( and(a1>=10, a1<=20), “Good job”, “Do it again”)
 Truth tables
 See discussion in class

Dr. K. Chen, 2015 3


Nested IF Statement

 =IF(SalesAMT>10,IF(SalesAMT>50,IF(SalesAMT>100,0.1,0.05),0.03),0.02)

 What is the discount rate if SalesAMT is $25?

Dr. K. Chen, 2015 4


Exercise

 Task 1: write an IF statement in E3 to determine the


letter grade of E2. Use AND() or OR() in IF statement to
answer the question.

 Task 2: do the same thing as Task 1 without using AND()


and OR().

Dr. K. Chen, 2015 5


Exercise – Nested IF Statement

 File: ifstatement.xlsx
 Task:

Dr. K. Chen, 2015 6


Exercise – IFERROR()

 File: Errortrap.xlsx
 Syntax: IFERROR(value, value_if_error)
 Task: Replace all errors with (VNF).

 Note: The IFERROR() can be used on any error (#DIV/0,


#VALUE!, #NAME?, #NUM!, #REF! …). See the
Errortypes.xlsx file for what cause these errors.
Dr. K. Chen, 2015 7
Error leads to Error
 Performing numeric calculations on cells containing
errors will most likely produce an error. (see E23).
 Task: replace all #N/A to empty strings
 Q: does the SUM function work after this?
 Syntax: AGGREGATE(function_num, options, array)
 Example:
 =AGGREGATE(1,6, E11:E16)  74.66667

Dr. K. Chen, 2015 8

You might also like