Uploaded by mehedi.hasan717

CBA Final-Lecture 4 Logical functions

advertisement
Logical FUNCTIONS
and values
Lecture 4
CBA
• Discuss the purpose of Excel conditional formatting options
• Explain how to apply, modify and remove conditional formatting based on cell contents
TRUE AND FALSE
A logical value can be one of only two values
TRUE
or
FALSE
3
TRUE
• The following statements are TRUE:
Fish live in water.
Deer live on land.
• The following statements are also TRUE:
3 is greater than 2
2 is less than 3
2 is less than or equal to 3
2 is less than or equal to 2
3 is greater than or equal to 2
3 is greater than or equal to 3
2 is equal to 2
2 is not equal to 3
4
FALSE
• The following statements are FALSE:
Fish live on land.
Deer live in water.
• The following statements are also FALSE:
2 is greater than 3
3 is less than 2
3 is less than or equal to 2
2 is greater than or equal to 3
2 is equal to 3
2 is not equal to 2
5
LOGICAL OPERATORS
•
In Excel the following "operators" are used
Operator
Meaning
>
greater than
<
less than
>=
greater than or equal to
<=
less than or equal to
=
equal to
<>
not equal to
•
Examples
3>2
3<2
true
false
6
LOGICAL FORMULAS
Formula View
Values View
7
IF FUNCTION
IF Functions are like programing they provide multiple answers
based on certain conditions.
IF function
The IF function checks whether a condition is met,
and returns one value if TRUE and another value if
FALSE.
Syntax: IF(logical_test,value_if_true,value_if_false)
Example:
IF(D2>C2,”INCREASE”,”OK”)
This formula checks to see if the value in column D
is greater than the value in column C.
If it is, it will show INCREASE in column E. If not, it
puts OK in column E.
ABSOLUTE
VALUE
EXAMPLE
The number to be evaluated is entered into cell A1
The formula is entered into cell B1
Engineering Computation: An Introduction Using
MATLAB and Excel
IF FUNCTION
Formula View
Values View
11
IF() FUNCTION
A
B
C
1
Name
Exam
Grade
2
Adams
87
Pass
3
Benson
92
Pass
4
Carson
68
Fail
5
Danson
78
Pass
D
E
F
6
=IF(B2>=70,”Pass”,”Fail”)
IF() FUNCTION
Form
– =IF(condition,
value-for-TRUE-case,
value-for-FALSE-case)
Example
– Assume: B2 contains semester average
– Then, in C2, we can have:
=IF(B2>=70, “Pass”, “Fail”)
NESTING IF STATEMENTS
Often, there will be more than two possible outputs for a given input
In MATLAB, we use the if-then-else function
In Excel, we must nest IF statements
Consider this example: we want to read in a numerical grade and convert it to
a letter grade on a scale of:
–
–
–
–
–
Greater than or equal to 90 = A,
Greater than or equal to 80 and less than 90 = B
Greater than or equal to 70 and less than 80 = C
Greater than or equal to 60 and less than 70 = D
Less than or equal to 60 = F
Engineering Computation: An Introduction Using
MATLAB and Excel
EXCEL FORMULA
Consider this first IF statement:
If true, “A” is entered into cell B1
If false, then another IF statement is encountered
Note the use of “>=” for greater than or equal to:
If just “>” (greater than) is used, then a grade of exactly 90
would be a B.
EXAMPLES
ALTERNATE SOLUTION
NOT
Takes ONLY ONE parameter
Returns the "opposite" of the value of the parameter
– returns FALSE if the parameter value is TRUE
– returns TRUE if the parameter value is FALSE
18
BASIC FORMULAS AND FUNCTIONS
IF function
The IF function checks whether a condition is met, and
returns one value if TRUE and another value if FALSE.
Syntax: IF(logical_test,value_if_true,value_if_false)
Example:
IF(D2>C2,”INCREASE”,”OK”)
This formula checks to see if the value in column D is
greater than the value in column C.
If it is, it will show INCREASE in column E. If not, it puts
OK in column E.
CONDITIONAL
FORMATTING
CONDITIONAL FORMATTING
• Conditional formatting in Excel is a tool that
allows you to change the appearance of a cell
or range of cells based on the contents of the
cells.
• There are several types of conditional
formatting rules built in to Excel and many
more options available through
customization.
• These options are helpful for highlighting
trends, mistakes in data, and variances that
fall outside an expected range.
CONDITIONAL FORMATTING
Highlight Cells Rules
• Choose one of the built in rules or choose ‘More
Rules’ for customizable options
• Great for finding zero values, values outside
normal ranges, negative values, duplicates, and
other specific amounts
• Also can be used for finding dates and text values
CONDITIONAL FORMATTING
Highlight Cells Rules
•
Enter any value in the first field, or you
can choose a cell in your workbook to
find amounts.
•
Defaults to Light Red Fill with Dark Red
Text, but can be changed to any
formatting.
•
Choose Custom Format if you want to
define the format. You can choose
Number styles, Fill colors, Cell borders,
and certain Font options
CONDITIONAL FORMATTING
Top/Bottom Rules
• Use these options to find values within the
selection that represent the highest and lowest
amounts or amounts that are above or below
average within the selection.
• Could be used for any selected group of cells,
columns or rows.
• You can use more than one on the same
selection, using different formats to
differentiate between them.
CONDITIONAL FORMATTING
Top/Bottom Rules
• In this example, we find the Top 10 Items in the
column and format them with Light Red Fill.
• The Top/Bottom Items and % can be changed to
include any number or percentage. (Top 20,
Bottom 5, etc.) Just change the number in the
dialog box.
CONDITIONAL FORMATTING
Top/Bottom Rules
Another example using Top 5% of values in the column.
Formatted to Green Fill with Dark Green Text.
CONDITIONAL FORMATTING
Data Bars
Data Bars can be used to visually interpret the
amounts within the selected range of cells.
Preset options are Gradient Filled Bars and Solid
Filled Bars in 6 different colors. The size of the bar
indicates the amount in comparison with the other
amounts in the selection.
Gradient blue
Solid orange
CONDITIONAL FORMATTING
Color Scales
• Color Scales are another way to visually
interpret values in a selected range of
cells.
• You can choose 2-color scales or 3-color
scales.
• 12 preset options available
• Scales are customizable
CONDITIONAL FORMATTING
Color Scales
• 2-color scales have one color for the highest
value in the selection and one for the lowest
value. Values in between are represented
with shaded gradations of the two colors.
• Minimum and Maximum colors can be
customized with the these types and any
value or colors.
2-scale Red/White
example
CONDITIONAL FORMATTING
Color Scales
• 3-color scales have a highest value
color, a lowest value color and a
midpoint color. The midpoint can also
be customized with the following types
and any value or color. The defaults
are shown in this window.
3-scale Blue/White/Red
example
CONDITIONAL FORMATTING
Icon Sets
• Using an Icon set adds picture icons to cells
based on the cell values. There are several
preset options and they are also fully
customizable.
• The default settings use percent, but you can
also set them to formula, number or
percentile.
• To customize a selected Icon Set, go to
Manage Rules.
CONDITIONAL FORMATTING
Icon Sets
• The default settings for the 3 icon sets are:
1. Greater than or equal to 67%
2. Less than 67% but Greater than or equal to
33%
3. Less than 33%
CONDITIONAL FORMATTING
Icon Sets
• The default settings for the 4 icon sets are:
1. Greater than or equal to 75%
2. Less than 75% but Greater than or equal
to 50%
3. Less than 50% but Greater than or equal
to 25%
4. Less than 25%
CONDITIONAL FORMATTING
Icon Sets
• The default settings for the 5 icon sets are:
1. Greater than or equal to 80%
2. Less than 80% but Greater than or equal to
60%
3. Less than 60% but Greater than or equal to
40%
4. Less than 40% but Greater than or equal to
20%
5. Less than 20%
CONDITIONAL FORMATTING
Icon Sets
Icons can be displayed in the cell next to the cell
contents, or they can be the only thing that displays in
the cell.
Check the Show Icon Only box to hide the
cell contents.
EXAMPLES OF COMPLEX NESTED
FUNCTION CALLS
=IF(AND(A2>A3, OR(B2=B3,C2<C3)), 500, 1000)
=IF(NOT(AND(A2>A3, OR(B2=B3,C2<C3))), 500, 1000)
=IF(AND(A2>A3, NOT(OR(B2=B3,C2<C3))), 500, 1000)
36
Download