conditional logic using excel “if” statements. logical testif trueif false did you finish your...

15
Conditional Logic Using Excel “IF” Statements

Upload: alaina-moreland

Post on 01-Apr-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

Conditional Logic Using Excel “IF” Statements

Page 2: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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

Page 3: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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

Page 4: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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  

Page 5: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

The basic form of an “If” statement is:

=IF(Logical Test is True,Then,Else)

Page 6: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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  

Page 7: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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

Page 8: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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  

Page 9: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

=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:

Page 10: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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  

Page 11: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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  

Page 12: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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  

Page 13: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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  

Page 14: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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 

Page 15: Conditional Logic Using Excel “IF” Statements. Logical TestIf TrueIf False Did you finish your dinner? You may have dessert. You may not have dessert

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., “).