2 / 6 · Basic
SUM, AVERAGE, COUNT, MIN and MAX
Six students, four scores, the word absent and an empty cell: AVERAGE divides by 4 here, not by 6, because it skips text and empty cells but counts the 0.
Jump to the 12 practice questionsYou will learn
- Tell COUNT from COUNTA, and a blank from a zero
- Choose the mean, median or mode
Before this: Absolute and mixed references
1Explain
A score sheet with one absence and one missing mark
Picture the score sheet in the lab below. Ana has 82, Chloe 91, Eli 0 and Fay 77. Ben was absent, so someone typed the word absent. Dev's test hasn't been marked yet, so his cell is empty. What is the class average? Count the cells and you might divide by 6. AVERAGE divides by 4 and gets 62.5, the same answer as someone with a calculator who skips Ben and Dev.
2Explain
Five functions, one rule
The rule behind that answer is short. SUM adds, AVERAGE gives the arithmetic mean, MIN and MAX give the smallest and largest number, and COUNT says how many numbers there are. All five take a range such as B2:B7, or several ranges separated by commas. These functions normally ignore text and blanks in a range. COUNT also ignores error values, but SUM and AVERAGE can pass an error to their result. Microsoft's AVERAGE page puts it plainly: text, logical values and empty cells in a range are ignored, but cells with the value zero are included.
3Problem
The class average
B2:B7 holds 82, absent, 91, (empty), 0, 77. What does =AVERAGE(B2:B7) return?
Hint
250 ÷ 4.
Solution
Answer: 62.5
Four numbers: (82 + 91 + 0 + 77) ÷ 4 = 250 ÷ 4 = 62.5.
4Problem
COUNT
Same cells. What does =COUNT(B2:B7) return?
Hint
Numbers only: 82, 91, 0, 77.
Solution
Answer: 4
82, 91, 0 and 77 are numbers; absent is text and one cell is empty.
5Problem
MIN
Same cells. What does =MIN(B2:B7) return?
Hint
Eli scored 0.
Solution
Answer: 0
Eli's 0 is a real number and the smallest one.
6Explore
A blank is not a zero
This is why a blank and a zero are not the same thing. A student who scored 0 pulls the average down. A student with no mark yet leaves it untouched. Microsoft's own example averages 10, 7, 9, 27 and 2 to get 11; add 5 as a second argument, =AVERAGE(A2:A6, 5), and it becomes 10, because 60 ÷ 6 = 10. And a range with no numbers at all? AVERAGE has nothing to divide by and returns #DIV/0!.
Like AVERAGE, the code keeps only numbers. An empty cell (null) changes nothing; a 0 pulls the mean down.
const cells = [82, 91, 77, null];
const nums = cells.filter((c) => typeof c === "number");
console.log(nums.reduce((a, b) => a + b, 0) / nums.length);83.333333333333337Problem
Blank or zero
Why does a blank score not lower the AVERAGE but a 0 does?
Hint
Which one is a number?
Solution
Answer: Empty cells are ignored; zeros are numbers and are included
A blank is omitted from both the sum and the count. A zero adds nothing to the sum but increases the count used by AVERAGE, so it can lower the mean.
8Problem
Microsoft's example
A2:A6 holds 10, 7, 9, 27, 2. What does =AVERAGE(A2:A6) return?
Hint
55 ÷ 5.
Solution
Answer: 11
55 ÷ 5 = 11, Microsoft's example.
9Problem
With 5 added
And =AVERAGE(A2:A6, 5)?
Hint
60 ÷ 6.
Solution
Answer: 10
(55 + 5) ÷ 6 = 10.
10Explain
Counting numbers, or counting filled cells
COUNT counts numbers only. Microsoft's example column holds a date, 19, 22.24, TRUE and #DIV/0!, and =COUNT(A2:A6) gives 3. The date counts, because a date is stored as a number. TRUE and the error do not. COUNTA counts every cell that isn't empty, whatever it holds, so the same column gives 5. Google's COUNTA help adds a trap worth knowing: zero-length text and spaces count too, so a cell whose formula returns "" looks blank and is still counted.
| Function | What it returns | Text in the range | Empty cells |
|---|---|---|---|
| SUM | total | ignored | ignored |
| AVERAGE | total ÷ count of numbers | ignored | ignored |
| COUNT | how many numbers | not counted | not counted |
| COUNTA | how many non-empty cells | counted | not counted |
| MIN / MAX | smallest / largest number | ignored | ignored |
11Problem
COUNTA
Same cells. What does =COUNTA(B2:B7) return?
Hint
Every cell that is not empty.
Solution
Answer: 5
Every non-empty cell counts, including absent.
12Problem
COUNT with a date and TRUE
A column holds a date, 19, 22.24, TRUE and #DIV/0!. What does COUNT return?
Hint
A date is a number; TRUE is not.
Solution
Answer: 3
The date, 19 and 22.24 are numbers; TRUE and the error are not counted.
13Problem
AVERAGE of text only
B2:B4 holds only text. What does =AVERAGE(B2:B4) return?
Hint
Zero numbers to divide by.
Solution
Answer: #DIV/0!
No numbers means a count of 0 to divide by.
14Explain
Three kinds of middle
Is the mean always the right middle value? No. Microsoft's AVERAGE page uses 2, 3, 3, 5, 7 and 10: the mean is 5, the median (the middle value) is 4, and the mode (the most frequent value) is 3. Both programs have MEDIAN and MODE for these. When one extreme number sits in the data, like a single 0 among scores in the 80s, the median describes a typical student better than the mean does.
| Measure | Formula | For 2, 3, 3, 5, 7, 10 |
|---|---|---|
| Mean | =AVERAGE(...) | 5 |
| Median (the middle value) | =MEDIAN(...) | 4 |
| Mode (the most frequent value) | =MODE(...) | 3 |
15Problem
The median
What is the median of 2, 3, 3, 5, 7, 10?
Hint
The middle of 2, 3, 3, 5, 7, 10 is between 3 and 5.
Solution
Answer: 4
The two middle values are 3 and 5; halfway between is 4.
16Problem
The mode
What is the mode of 2, 3, 3, 5, 7, 10?
Hint
The value that appears twice.
Solution
Answer: 3
3 appears twice and every other value once, so the mode is 3.
17Explain
Argument limits and empty ranges
The two programs differ on one small point, the number of arguments a function accepts. Excel's limits page gives 255. Google's help for AVERAGE and COUNTA says Sheets takes any number. With ranges you will never notice either limit. The handling of numbers, text and blanks described above is the same in both, so a sheet built in one gives the same answers in the other.
18Problem
Arguments in Excel
How many arguments can an Excel function take?
Hint
The same limit as SUM.
Solution
Answer: 255
Excel's limits page: 255. Google Sheets accepts any number.
19Explore
Practice in the grid
MIN and MAX follow the same rule. With no numbers in the range, both return 0 instead of an error, and that 0 looks like a real result. If a price list reports a lowest price of 0, check whether there really is a free item, or whether the column simply holds no numbers.
Drag to turn. Scroll or pinch to zoom.
20Practice
AVERAGE that skips text and blanks
count and countA are given. Finish average(cells): add the numbers and divide by how many numbers there are; with no numbers at all, return "#DIV/0!" like a spreadsheet.
62.5
4
5
#DIV/0!const isNum = (c) => typeof c === "number";
function count(cells) {
return cells.filter(isNum).length;
}
function countA(cells) {
return cells.filter((c) => c !== null).length;
}
function average(cells) {
return 0;
}
const scores = [82, "absent", 91, null, 0, 77];
console.log(average(scores));
console.log(count(scores));
console.log(countA(scores));
console.log(average(["a", "b"]));
Hint
Divide by count, not by the number of cells.
A solution
const isNum = (c) => typeof c === "number";
function count(cells) {
return cells.filter(isNum).length;
}
function countA(cells) {
return cells.filter((c) => c !== null).length;
}
function average(cells) {
const nums = cells.filter(isNum);
if (nums.length === 0) return "#DIV/0!";
return nums.reduce((a, b) => a + b, 0) / nums.length;
}
const scores = [82, "absent", 91, null, 0, 77];
console.log(average(scores));
console.log(count(scores));
console.log(countA(scores));
console.log(average(["a", "b"]));21Explain
Common mistakes
Typing 0 for a test that hasn't been marked yet.
AVERAGE counts the 0, so the average drops. Leave the cell empty until there is a real mark.
Using COUNT to count names or Yes answers.
COUNT sees only numbers, so a column of text gives 0. COUNTA counts filled cells.
Trusting COUNTA on a column of formulas that return "".
Google's help says zero-length text is counted, so cells that look blank still add to the total.
Adding cells with + when one of them holds text.
With absent in B3, =B2+B3 gives #VALUE!, while =SUM(B2:B3) skips the text. Microsoft's #VALUE! page suggests a function such as SUM for this reason.
22
Summary
- SUM, AVERAGE, MIN, MAX and COUNT read only the numbers in a range.
- Empty cells are ignored; zeros are counted.
- COUNT counts numbers; COUNTA counts every non-empty cell, even "".
- AVERAGE of no numbers is #DIV/0!.