Conditional Logic Using Excel “IF” Statements
Logical Test If True If False
Did you finish your dinner?
You may have dessert.
You may not have dessert.
Are you a registered voter?
You may vote in the election.
You may not vote in the election.
Does the animal have a backbone?
It is classified as a vertebrate.
It is classified as an invertebrate.
Do you want to mail the letter?
You will need to get a stamp.
You will not need to get a stamp.
Some “plain-English” examples ofconditional logic statements
My grading scale—(yours might be different)
From To Ltr Grade Pass or Fail
>=0% <59.5% F Fail
>=59.5% <69.5% D Pass
>=69.5% <79.5% C Pass
>=79.5% <89.5% B Pass
>=89.5% <=100% A Pass
Example 1: A simple conditional logic test
Based on the grading scale shown in the previous slide, create a conditional logic statement that determines if each of the values in column K (“Pct of Tot Pts Possible”) represents a passing grade (“Pass”) or a failing grade (“Fail”), and store the results in column M ( “Pass or “Fail”).
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6
3 73
4 59.4
5 79.8
6 67.2
The basic form of an “If” statement is:
=IF(Logical Test is True,Then,Else)
Logical Test If True If False
Is K2>=59.5? M2=Pass M2=Fail
=IF(K2>=59.5,“Pass","Fail")
The conditional logic statement for the first case is:
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6 Pass
3 73
4 59.4
5 79.8
6 67.2
For the value in K2 (i.e., 73), the conditional logic statement would be: =IF(K2>=59.5,”Pass”,”Fail”)For the value in K3 (i.e., 89.6), the conditional logic statement would be: =IF(K3>=59.5,”Pass”,”Fail”)For the value in K4 (i.e., 59.4), the conditional logic statement would be: =IF(K4>=59.5,”Pass”,”Fail”)For the value in K5 (i.e., 79.8), the conditional logic statement would be: =IF(K5>=59.5,”Pass”,”Fail”)For the value in K6 (i.e., 67.2), the conditional logic statement would be: =IF(K6>=59.5,”Pass”,”Fail”)
The conditional logic statements for all cases are:
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6 Pass
3 73 Pass
4 59.4 Fail
5 79.8 Pass
6 67.2 Pass
Example 2: “Nested” conditional logic tests
Based on the grading scale shown previously, create a conditional logic statement that will determine the letter grade for each of the values in column K (“Pct of Tot Pts Possible”), and store the results in column L (“Ltr Grade”).
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6
3 73
4 59.4
5 79.8
6 67.2
=IF(K2>=89.5,"A",IF(K2>=79.5,"B",IF(K2>=69.5,"C",IF(K2>=59.5,"D","F"))))
Displayed on the next four slides are itsfour ”nested” component parts…
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6 A
3 73
4 59.4
5 79.8
6 67.2
The conditional logic statement for the first case is:
Logical Test If True If False
Is K2>=59.5? L2=D L2=F
Is K2>=69.5? L2=C Steps in Blue
Is K2>=79.5? L2=B Steps in Blue
Is K2>=89.5? L2=A Steps in Blue
=IF(K2>=89.5,"A",IF(K2>=79.5,"B",IF(K2>=69.5,"C",IF(K2>=59.5,"D","F"))))
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6 D
3 73
4 59.4
5 79.8
6 67.2
Logical Test If True If False
Is K2>=59.5? L2=D L2=F
Is K2>=69.5? L2=C Steps in Blue
Is K2>=79.5? L2=B Steps in Blue
Is K2>=89.5? L2=A Steps in Blue
=IF(K2>=89.5,"A",IF(K2>=79.5,"B",IF(K2>=69.5,"C",IF(K2>=59.5,"D","F“))))
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6 C
3 73
4 59.4
5 79.8
6 67.2
Logical Test If True If False
Is K2>=59.5? L2=D L2=F
Is K2>=69.5? L2=C Steps in Blue
Is K2>=79.5? L2=B Steps in Blue
Is K2>=89.5? L2=A Steps in Blue
=IF(K2>=89.5,"A",IF(K2>=79.5,"B",IF(K2>=69.5,"C",IF(K2>=59.5,"D","F“))))
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6 B
3 73
4 59.4
5 79.8
6 67.2
Logical Test If True If False
Is K2>=59.5? L2=D L2=F
Is K2>=69.5? L2=C Steps in Blue
Is K2>=79.5? L2=B Steps in Blue
Is K2>=89.5? L2=A Steps in Blue
=IF(K2>=89.5,"A",IF(K2>=79.5,"B",IF(K2>=69.5,"C",IF(K2>=59.5,"D","F"))))
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6 A
3 73
4 59.4
5 79.8
6 67.2
For the value in K2 (i.e., 73), the conditional logic statement would be: =IF(K2>=89.5,"A",IF(K2>=79.5,"B",IF(K2>=69.5,"C",IF(K2>=59.5,"D","F"))))For the value in K3 (i.e., 89.6), the conditional logic statement would be: =IF(K3>=89.5,"A",IF(K3>=79.5,"B",IF(K3>=69.5,"C",IF(K3>=59.5,"D","F"))))For the value in K4 (i.e., 59.4), the conditional logic statement would be: =IF(K4>=89.5,"A",IF(K4>=79.5,"B",IF(K4>=69.5,"C",IF(K4>=59.5,"D","F"))))For the value in K5 (i.e., 79.8), the conditional logic statement would be: =IF(K5>=89.5,"A",IF(K5>=79.5,"B",IF(K5>=69.5,"C",IF(K5>=59.5,"D","F"))))For the value in K6 (i.e., 67.2), the conditional logic statement would be: =IF(K6>=89.5,"A",IF(K6>=79.5,"B",IF(K6>=69.5,"C",IF(K6>=59.5,"D","F"))))
The conditional logic statements for all cases are:
K L M
1 Pct of Tot Pts Possible Ltr Grade Pass or Fail
2 89.6 A
3 73 C
4 59.4 F
5 79.8 B
6 67.2 D
Some Important Things to Remember About Nested Conditional Logic Statements:
• You are limited to a maximum of 7 logical tests when creating nested conditional logic statements.
• Separate the 3 parameters for each conditional logic statement with commas.
• For each conditional logic statement, you must enclose its parameters inside a separate set of parenthesis.
• For each conditional logic statement, if the “then” and “else” parameters are fixed characters (like letters or numbers), enclose them in a pair of double quotes (i.e., “).