0% found this document useful (0 votes)
9 views

Excel Math 5

The document discusses various logic and conditional functions in Microsoft Excel including COUNTIf(), SUMIf(), and IFS. It covers combining logic functions like AND, OR, and NOT. It also covers worksheet functions like IF, IFNA, IFERROR, and conditional functions like COUNTIF, SUMIF, AVERAGEIF. Examples are provided for each function.

Uploaded by

Danny Dar Win
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Excel Math 5

The document discusses various logic and conditional functions in Microsoft Excel including COUNTIf(), SUMIf(), and IFS. It covers combining logic functions like AND, OR, and NOT. It also covers worksheet functions like IF, IFNA, IFERROR, and conditional functions like COUNTIF, SUMIF, AVERAGEIF. Examples are provided for each function.

Uploaded by

Danny Dar Win
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Excel Math 5: More Logic

CountIf(), SumIf(), Ifs()

[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

Pandora Rose Cowart


Education/Training Specialist
UF Health IT Training

C3-013 Communicore (352) 273-5051


PO Box 100152 [email protected]
Gainesville, FL 32610-0152 http://training.health.ufl.edu

Class Evaluation: https://ufl.qualtrics.com/jfe/form/SV_1Ojjkl6lRsKV3XT

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

Not Equal <> 5<>5 FALSE 5<>10 TRUE

Greater Than > 5>5 FALSE 5>10 FALSE

Greater Than or Equal >= 5>=5 TRUE 5>=10 FALSE

Less Than < 5<5 FALSE 5<10 TRUE

Less Than or Equal <= 5<=5 TRUE 5<=10 TRUE

You can also use the words TRUE or FALSE at any point in an equation.

Combining Logic Functions


We can use the logic functions AND, OR, and NOT statements to test several conditions at once and get
a final TRUE/FALSE answer.

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

=AND(TRUE, TRUE) TRUE


=AND(TRUE, FALSE) FALSE
=AND(FALSE, FALSE) FALSE

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

IF Error Worksheet Functions


Newer versions of Microsoft Excel offer IFNA and IFERROR to simplify our equations.

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"))

It often helps to draw a Logic Tree

A10<=100 A10=100 B2>C2

Over Budget OK SUM(B5:B15) "" Over Budget B2+50 > C2

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…)

Compare the functions to see which you feel is easier to read:


=IFS(A2>89, "A", A2>79, "B", A2>69, "C", A2>59, "D", TRUE, "F")
=IF(A2>89, "A", IF(A2>79, "B", IF(A2>69, "C", IF(A2>59, "D", "F"))))

=IFS(B2>C2, "Over Budget", B2+50>C2,"Getting close", TRUE, "OK")


=IF(B2>C2, "Over Budget", IF(B2+50>C2,"Getting close", "OK")

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.

=SUMIF(A2:A5, ">250000", B2:B5) $49, 000


=SUMIF(A2:A5, "<250000", B2:B5) $20, 000

4
SUMIFs
Adds the cells specified by a given criteria (Multiple)
Syntax: SUMIFS(sum_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)

Sum_range - (required) The range of cells to sum.


Criteria_range1 - (required) The range that is tested using Criteria1.
Criteria_range1 and Criteria1 set up a search pair whereby a range is searched for specific
criteria. Once items in the range are found, their corresponding values in Sum_range
are added.
Criteria1 - (required) The criteria that defines which cells in Criteria_range1 will be added. For
example, criteria can be entered as 32, ">32", B4, "apples", or "32".
Criteria_range2, criteria2, … (optional)

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.

Syntax: AVERAGEIF(range, criteria, [average_range])

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.

Syntax: AVERAGEIFS(average_range, criteria_range1, criteria1, [criteria_range2, criteria2], ...)

Average_range Required. One or more cells to average, including numbers or names, arrays,
or references that contain numbers.

Criteria_range1, criteria_range2, … Criteria_range1 is required, subsequent criteria_ranges


are optional. 1 to 127 ranges in which to evaluate the associated criteria.

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)

=CountIFs(Range, Critera, Range, Criteria, …)


CountIfs is equivalent the sum of multiple CountIF statements.

=SumIF( SearchRange, Criteria, SumRange)


SumIf adds all the values in the SumRange, when your SearchRange matches your logic test
(criteria)

=SumIF( SumRange, SearchRange, Criteria, SearchRange, Criteria, …)


SumIfs adds all the values in the SumRange when the criteria matches each SearchRange.

=AverageIf(range, criteria, [average_range])


AverageIf averages all the values in the Average_range, when your SearchRange matches your
logic test

=AverageIF( AverageRange, SearchRange, Criteria, SearchRange, Criteria, …)


AverageIfs adds all the values in the AverageRange when the criteria matches each
SearchRange.

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

Syntax: SWITCH(Expression, Match1, Return1, Match2, Return2,…, ReturnForNoMatch)

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"))

3. Letter Grade Nested IF


=IF(A2>=90,"A",IF(A2>=80,"B",IF(A2>=70,"C",IF(A2>=60,"D","F"))))

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

1. Sum all of the Sales


Add all the values in column Sale

=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

SUMIFS($F:$F, $G:$G, $I11, $E:$E, J$10)

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

5. Sum of Sales by Sales Person, Quarter, and Fiscal Year 18-19 I J


Sum all the Sales when – Sales Person matches the value in cell I19 17 FY 18-19
AND Quarter matches the value in J18 18 Sales Person 1st Qtr
19 Ann $5,550
AND Fiscal Year matches the value in I17
20 Dan $5,184

SUMIFS($F:$F, $G:$G, $I19, $E:$E, J$18, $B:$B, $I$17)

Where do we put the dollar signs?

$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

SUMIFS($F:$F, $G:$G, $I27, $E:$E, J$26, $B:$B, $I$25)

10
Class Exercise – Summary Sheet - PivotTable
You may prefer to use a PivotTable to let Excel do the math.

• Put yourself in Cell A1


• From the Insert Tab, choose PivotTable
• Click OK

1. Sum all of the Sales


Click on the check box for Sale, and Excel will show you the Sum of the sales.

2. Sum of Sales by Sales Person


Click the check box for Sales Person and Excel will add the labels to the
Row headings.

3. Sum of Sales by County


Uncheck the Sales Person, and check the County.

4. Sum of Sales by Sales Person and County


Move County to the Column section, and click the check box for Sales
Person again.

5. Sum of Sales by Sales Person, Quarter, and Fiscal Year 18-19


Uncheck the County, and move the Quarter to the Column
Group

Add Fiscal Year to the Filter Group

Change the filter to FY 18-19

6. Sum of Sales by Sales Person, Quarter, and Fiscal Year 19-20


Change the filter to FY 19-20

11

You might also like