Excel Math 5
Excel Math 5
[email protected]
Excel Math 5: More Logic – CountIf(), SumIf(), Ifs()
1.0 hour
Logic Test (True/False functions) ........................................................................................ 1
Combining Logic Functions ................................................................................................. 1
AND ................................................................................................................................. 1
OR .................................................................................................................................... 1
NOT ................................................................................................................................. 1
IS Worksheet Functions ...................................................................................................... 2
IF Error Worksheet Functions ............................................................................................. 2
IFNA ................................................................................................................................. 2
IFERROR........................................................................................................................... 2
IF Worksheet Function ........................................................................................................ 3
IF ...................................................................................................................................... 3
IFS .................................................................................................................................... 3
Conditional Functions ......................................................................................................... 4
COUNTIF .......................................................................................................................... 4
SUMIF .............................................................................................................................. 4
SUMIFs ............................................................................................................................ 5
AVERAGEIF ...................................................................................................................... 5
Conditional Function Summary ...................................................................................... 6
SWITCH................................................................................................................................ 6
Class Exercise - Grades ........................................................................................................ 7
Class Exercise – "Flags" ....................................................................................................... 8
Class Exercise – Summary Sheet ......................................................................................... 9
Class Exercise – Summary Sheet - PivotTable ................................................................... 11
Updated: 05/27/2021
Logic Test (True/False functions)
Most of Microsoft Excel's logic functions will return a TRUE or FALSE, but simple True or False values can
be found with comparisons using the equal, greater than, and less than symbols
Equal = 5=5 TRUE 5=10 FALSE
You can also use the words TRUE or FALSE at any point in an equation.
AND
Returns TRUE if all its arguments are TRUE
Syntax: AND(logical1, logical2, ...)
If the specified range contains no logical values, returns the #VALUE! error.
ALL Logic
must be true
OR
Returns TRUE if any argument is TRUE
Syntax: OR(logical1, logical2, ...)
If the specified range contains no logical values, returns the #VALUE! error. ANY Logic
can be true
=OR(TRUE, TRUE) TRUE
=OR(TRUE, FALSE) TRUE
=OR(FALSE, FALSE) FALSE
NOT
Reverses the value of its argument.
Syntax: NOT(logical)
=NOT(FALSE) TRUE
=NOT(TRUE) FALSE
1
IS Worksheet Functions
This set of functions return TRUE or FALSE based if the match the following conditions:
FUNCTION RETURNS TRUE IF
ISBLANK Value refers to an empty cell.
ISERR Value refers to any error value except #N/A.
ISERROR Value refers to any error value (#N/A, #VALUE!, #REF!,
#DIV/0!, #NUM!, #NAME?, or #NULL!).
ISLOGICAL Value refers to a logical value.
ISNA Value refers to the #N/A (value not available) error value.
ISNONTEXT Value refers to any item that is not text. (Note that this
function returns TRUE if the value refers to a blank cell.)
ISNUMBER Value refers to a number.
ISREF Value refers to a reference.
ISTEXT Value refers to text.
A1=5 A2=Div/0
=ISBLANK(A1) FALSE =ISBLANK(A2) FALSE
=ISERR(A1) FALSE =ISERR(A2) TRUE
=ISERROR(A1) FALSE =ISERROR(A2) TRUE
=ISLOGICAL(A1) FALSE =ISLOGICAL(A2) FALSE
=ISNA(A1) FALSE =ISNA(A2) FALSE
=ISNONTEXT(A1) TRUE =ISNONTEXT(A2) TRUE
=ISNUMBER(A1) TRUE =ISNUMBER(A2) FALSE
=ISREF(A1) TRUE =ISREF(A2) TRUE
=ISTEXT(A1) FALSE =ISTEXT(A2) FALSE
IFNA
Returns the value you specify if a formula returns the #N/A error value; otherwise it returns the result of
the formula.
IFNA(value, value_if_na)
The IFNA function syntax has the following arguments.
IFERROR
Returns the value you specify if a formula returns a #N/A, #VALUE!, #REF!, #DIV/0!, #NUM!, #NAME?, or
#NULL!. Error value; otherwise it returns the result of the formula.
IFERROR(value, value_if_error)
The IFERROR function syntax has the following arguments:
2
IF Worksheet Function
The TRUE or FALSE can be used as the "logic_test" in our conditional statements. We can vary the
answer depending on the logic test result.
IF
Specifies a logical test to perform
Syntax: IF(logical_test, value_if_true, value_if_false)
When the value_if_true and value_if_false arguments are evaluated, IF returns the value
returned by those statements.
Examples:
=IF(A10<=100, "Within budget", "Over budget")
=IF(A10=100, SUM(B5:B15), "")
=IF(B2>C2, "Over Budget", IF(B2+50>C2,"Getting close", "OK"))
Getting Close OK
IFS
Specifies multiple logical tests to perform
The IFS function checks whether one or more conditions are met, and returns a value that
corresponds to the first TRUE condition. IFS can take the place of multiple nested IF statements,
and is much easier to read with multiple conditions.
Syntax: IF(logical_test1, value_if_true1, logical_test2, value_if_true2…)
3
Conditional Functions
COUNTIF
Counts the number of nonblank cells that meet the given criteria
Syntax: COUNTIF(range, criteria)
Range is the range of cells from which you want to count cells. A B
Criteria is the criteria in the form of a number, expression, or text that 1 Apples 32
defines which cells will be counted. For example, criteria can be
expressed as 32, "32", ">32", "apples". 2 Oranges 53
3 Peaches 75
=COUNTIF(A1:A4, "apples") 2 4 Apples 86
=COUNTIF(B1:B4, ">55") 2
COUNTIFS
Counts the number of nonblank cells across multiple ranges and counts the number of times all criteria
are met. Search Range, Count if matches Criteria + Search Range, Count if matches Criteria + …
Syntax: COUNTIFS(criteria_range1, criteria1, [criteria_range2, criteria2]…)
criteria_range1 Required. The first range in which to evaluate the associated criteria.
criteria1 Required. The criteria in the form of a number, expression, cell reference, or text
that define which cells will be counted. For example, criteria can be expressed as 32,
">32", B4, "apples", or "32".
criteria_range2, criteria2, ... Optional. Additional ranges and their associated criteria. Up to
127 range/criteria pairs are allowed. You can use the wildcard characters— the
question mark (?) and asterisk (*) — in criteria. A question mark matches any single
character, and an asterisk matches any sequence of characters. If you want to find an
actual question mark or asterisk, type a tilde (~) before the character.
A B
SUMIF
Adds the cells specified by a given criteria 1 Value Commission
Syntax: SUMIF(range, criteria, sum_range) 2 $100, 000 $5, 000
Range is the range of cells you want evaluated. 3 $200, 000 $15, 000
Criteria is the criteria in the form of a number, expression, or
4 $300, 000 $21, 000
text that defines which cells will be added. For
example, criteria can be expressed as 32, "32", ">32", 5 $400, 000 $28, 000
"apples".
Sum_range are the actual cells to sum. The cells in sum_range are summed only if their
corresponding cells in range match the criteria. If sum_range is omitted, the cells in
range are summed.
4
SUMIFs
Adds the cells specified by a given criteria (Multiple)
Syntax: SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)
Additional ranges and their associated criteria. You can enter up to 127 range/criteria pairs.
AVERAGEIF
Returns the average (arithmetic mean) of all the cells in a range that meet a given criteria.
Range - Required. One or more cells to average, including numbers or names, arrays, or
references that contain numbers.
Criteria - Required. The criteria in the form of a number, expression, cell reference, or text that
defines which cells are averaged. For example, criteria can be expressed as 32, "32",
">32", "apples", or B4.
Average_range - Optional. The actual set of cells to average. If omitted, range is used.
AVERAGEIFS
Returns the average (arithmetic mean) of all cells that meet multiple criteria.
Average_range Required. One or more cells to average, including numbers or names, arrays,
or references that contain numbers.
Criteria1, criteria2, ... Criteria1 is required, subsequent criteria are optional. 1 to 127 criteria
in the form of a number, expression, cell reference, or text that define which cells will
be averaged. For example, criteria can be expressed as 32, "32", ">32", "apples", or B4.
5
Conditional Function Summary
=CountIF( Range, Criteria)
CountIf counts all the values in the selection (range) that match your logic test (criteria)
SWITCH
The SWITCH function evaluates one value (called the expression) against a list of values, and returns the
result corresponding to the first matching value.
You may choose this over an IF or vLookup statement when the values are an exact match.
SWITCH only performs an exact match, so you can't include logical operators like greater than (>) or less
than (<) in the logic used to determine a match. You can work around this by
Score Value A1 contains our score. To find the value of that score with Swtich:
3 Good =SWITCH(A1, 3, "Good", 2, "Okay", 1, "Not Good")
2 Okay
1 Not Good You can build the table and use the cell references instead of typing in the values.
=SWITCH(A1,$F$2,$G$2,$F$3,$G$3,$F$4,$G$4)
6
Class Exercise - Grades A B
1. Grade Pass/Fail 1 Grades Letter Grade
=IF(A2>=70,"Pass","Fail")
2 71
If(Grade >= 70 )
3 90
4 66
5 75
6 82
7 81
Pass Fail 8 53
9 79
10 94
2. Grade Pass/Fail/Withdraw
=IF(A2="W", "Withdrawn", IF(A2>=70,"Pass","Fail"))
7
Class Exercise – "Flags"
You may have heard the word "flagged" in a negative context, usually in the context of a Red Flag
warning. But this
1. Nested IF
=IF(E:E="Gainesville",IF(I:I>2000,"x",""),"")
=IF(H:H="Alachua",if(E:E<>"Gainesville","x",""),"") =IF(H:H="Bradford","x",IF(I:I>2300,"x","")
2. AND Logic
=IF(AND(H:H="Alachua",E:E<>"Gainesville"),"x","")
3. OR Logic
=IF(OR(H:H="Bradford",I:I>2300),"x","")
8
Class Exercise – Summary Sheet
A B C D E F G
1 Date Fiscal Year Quarter Acct# County Sale Sales Person
2 7/1/2018 FY 18-19 1st Qtr 362-549 Alachua $48 Ann
3 7/1/2018 FY 18-19 1st Qtr 569-214 Bradford $48 Dan
4 7/1/2018 FY 18-19 1st Qtr 509-809 Alachua $46 Bob
5 7/1/2018 FY 18-19 1st Qtr 935-093 Alachua $40 Dan
6 7/1/2018 FY 18-19 1st Qtr 922-726 Alachua $34 Dan
7 7/1/2018 FY 18-19 1st Qtr 116-814 Alachua $31 Ann
8 7/1/2018 FY 18-19 1st Qtr 509-809 Alachua $27 Bob
9 7/1/2018 FY 18-19 1st Qtr 658-578 Alachua $25 Bob
=SUM(F:F)
I J
2. Sum of Sales by Sales Person 3 Sales Person Total Sales
If the Sales Person matches the value in cell I4, sum its values in Sale 4 Ann $39,407
5 Dan $38,840
J4: =SUMIF(G:G, I4,F:F)
L M
3. Sum of Sales by County 3 County Total Sales
If the County matches the value in cell L4, sum its values in Sale 4 Alachua $109,891
5 Bradford $6,799
M4: =SUMIF(E:E,L4,F:F)
I J
4. Sum of Sales by Sales Person and County 10 Sales Person Alachua
Sum all the Sales when – Sales Person matches the value in cell I11 11 Ann $28,531
AND County matches the value in J10 12 Dan $28,315
Because we are now filling/copying the formula across, we need to think about the Absolute vs
Relative references, which values are "Forced", where do we put the dollar signs?
$F:$F - The County column must stay in place as we fill the equation across, lock all.
$G:$G - The Sales Person column must stay in place as we fill the equation across, lock all.
$I11 - The Sales Person match must stay in Column I as we move across but the Row number
can change. Lock the column, not the row.
$E:$E - The Sale column must stay in place as we fill the equation across, lock all.
J$10 - The County match must stay in Row 10 as we move down but the column number can
change. Lock the row, not the column.
9
A B C D E F G
1 Date Fiscal Year Quarter Acct# County Sale Sales Person
2 7/1/2018 FY 18-19 1st Qtr 362-549 Alachua $48 Ann
3 7/1/2018 FY 18-19 1st Qtr 569-214 Bradford $48 Dan
4 7/1/2018 FY 18-19 1st Qtr 509-809 Alachua $46 Bob
5 7/1/2018 FY 18-19 1st Qtr 935-093 Alachua $40 Dan
6 7/1/2018 FY 18-19 1st Qtr 922-726 Alachua $34 Dan
7 7/1/2018 FY 18-19 1st Qtr 116-814 Alachua $31 Ann
8 7/1/2018 FY 18-19 1st Qtr 509-809 Alachua $27 Bob
9 7/1/2018 FY 18-19 1st Qtr 658-578 Alachua $25 Bob
$F:$F - The Sale column must stay in place as we fill the equation across, lock all.
$G:$G - The Sales Person column must stay in place as we fill the equation across, lock all.
$I19 - The Sales Person match must stay in Column I as we move across but the Row number
can change. Lock the column, not the row.
$E:$E - The Quarter column must stay in place as we fill the equation across, lock all.
J$18 - The Quarter match must stay in Row 18 as we move down but the column number can
change. Lock the row, not the column.
$E:$E - The Fiscal Year column must stay in place as we fill the equation across, lock all.
$I$17 - The Fiscal Year match will stay the same, lock all.
I J
6. Sum of Sales by Sales Person, Quarter, and Fiscal Year 19-20
25 FY 19-20
Sum all the Sales when – Sales Person matches the value in cell I27 26 Sales Person 1st Qtr
AND Quarter matches the value in J26 27 Ann $4,319
AND Fiscal Year matches the value in I25 28 Dan $4,984
10
Class Exercise – Summary Sheet - PivotTable
You may prefer to use a PivotTable to let Excel do the math.
11