Sub topic 3
Adding values with SUM
SUM is the function you will write most often in Google Sheets. This chapter covers how it reads a range, what it skips, how it differs from the + operator, and the mistakes that produce wrong totals without any error message.
This chapter assumes you can type data and formulas into cells. It also assumes you know cell addresses such as B2 and that a range such as B2:B6 means "every cell from B2 down to B6". The next chapters cover multiple arguments, data types, and whole-column references in more depth, so this chapter only previews them.
The working model
SUM takes one or more arguments and returns the total of every number it finds in them. An argument can be a single cell, a range, or a typed number. The function walks through each cell in each argument, keeps the numbers, discards everything else, and adds the numbers.
=SUM(B2:B6)Suppose your sheet looks like this:
| Row | A | B |
|---|---|---|
| 1 | Item | Units sold |
| 2 | Apples | 120 |
| 3 | Pears | 85 |
| 4 | Plums | 40 |
| 5 | Figs | 55 |
| 6 | Limes | 30 |
Typing =SUM(B2:B6) into B7 returns 330, which is 120 + 85 + 40 + 55 + 30. The formula keeps pointing at B2:B6. If you change B4 from 40 to 50, the total in B7 becomes 340 immediately.
Ways to write the same total
All of these return 330 for the table above:
=SUM(B2:B6)
=SUM(B2, B3, B4, B5, B6)
=B2+B3+B4+B5+B6The first form is the one to use. The second is the same as the first but longer. The third uses the + operator and behaves differently in edge cases, covered below.
You can also build a total without typing. Select B2:B6 and look at the bottom-right corner of the window. Sheets shows a quick "Sum: 330" there. This is a preview and does not write anything into the sheet. If you select an empty cell below the data and click the Σ button in the toolbar, then choose Sum, Sheets inserts =SUM(B2:B6) for you. Check that the range it guessed is the one you meant.
What SUM skips
The most useful property of SUM is that it skips cells it cannot add. Compare it with the + operator. Add a note in B4:
| Row | A | B |
|---|---|---|
| 4 | Plums | n/a |
=SUM(B2:B6)returns 290. It ignores "n/a".=B2+B3+B4+B5+B6returns#VALUE!, because+cannot add text.
Empty cells behave differently. In + they count as 0, and in SUM they are skipped. Both give the same total, so you will rarely notice.
This skipping is convenient but can hide mistakes. Two cases cause trouble in practice:
- Numbers stored as text. If you paste data from a website or a CSV file, a value such as
85may be text, not a number. It is usually left-aligned in the cell, while real numbers are right-aligned.SUMskips it silently, and your total comes out low with no warning. - Text notes in a numeric column. A cell reading "TBD" is skipped, which is often what you want. But a typo such as
1O0(letter O instead of zero) is also skipped.
The next chapters cover this in detail. For now, COUNT is the quickest check you have for "did SUM see every row I expected?"
Errors inside the range
SUM skips text, but it does not skip error values. If any cell in the range holds an error such as #N/A or #DIV/0!, the whole SUM returns that error.
| Row | A | B |
|---|---|---|
| 2 | Apples | 120 |
| 3 | Pears | #N/A |
| 4 | Plums | 40 |
Here =SUM(B2:B4) returns #N/A. The fix is to correct the source cell, not to edit the SUM. The error is telling you that a value upstream is broken. Wrapping the total in IFERROR hides the message but gives a wrong or missing total, so use it only when you have decided that a blank result is acceptable. The IFERROR chapter covers that decision.
Ranges that move
A range written as B2:B6 is a fixed reference. Its behavior depends on how the sheet changes.
- Insert a row in the middle (for example, between rows 3 and 4). The range grows to
B2:B7, and the new row is included automatically. - Insert a row at the end, directly below row 6. The range does not grow. The new row is outside
B2:B6and is not counted. - Insert a row at the top, above row 2. The range shifts to
B3:B7and the new row is not included.
The end-of-range case catches many people. One common habit avoids it: include the empty row above the total in your range, or put the total above the data, so adding rows below it needs no edit.
=SUM(B2:B100)A larger fixed range such as this one works well when you expect the list to grow. The empty cells contribute nothing. If you put the total in B101 or lower, it stays outside the range, so there is no circular reference.
Using a typed number or a calculation
An argument does not have to come from a cell. You can add a fixed value, such as a shipping fee:
=SUM(B2:B6, 15)This returns 345. The following chapter covers combining several ranges and values. At this level, remember only that each argument is handled the same way: numbers are added, and anything else is handled by the rules above.
Typed values follow stricter rules than range contents. A text literal that looks like a number, such as "5", is converted and added. A text literal that cannot be converted, such as "abc", causes #VALUE!. This differs from cells in a range, where text is skipped without complaint.
Choosing between SUM and +
| Situation | Use |
|---|---|
| Adding a column or row of values | `SUM` |
| Adding two or three specific cells | Either; `+` reads more naturally |
| The data may contain text notes or blanks | `SUM`, because `+` returns `#VALUE!` on text |
| You want an error when a cell is not a number | `+`, because it exposes the bad cell |
The last row shows that the strictness of + can be an advantage. If you would prefer a loud failure over a silent skip, use + on a small set of cells.
Quick checklist for a trustworthy total
- Select the range and compare the "Sum:" preview with your formula result.
- Use
COUNTon the same range and confirm the count equals the number of rows you expect. - Check that the total cell is outside the range.
- If the data will grow, make sure the range covers the new rows.
- Read any error result as a pointer to a bad cell in the range.
Exercise
Cells B2:B6 contain 10, 20, the text "n/a", 30, and an empty cell, in that order. What do =SUM(B2:B6) and =B2+B3+B4+B5+B6 each return?
Show answer
=SUM(B2:B6) returns 60, because it adds 10, 20, and 30 and skips the text and the blank cell. =B2+B3+B4+B5+B6 returns #VALUE!, because the + operator cannot add the text "n/a". The empty cell alone would have counted as 0.
Exercise
You use =SUM(B2:B6) on a column of five order totals and get 250, but you expected 310. =COUNT(B2:B6) returns 4. What is the most likely cause, and how can you find the cell?
Show answer
One cell holds a value that is not a real number, most likely a number stored as text, such as pasted data. SUM skipped it, and COUNT did not count it, so the count is 4 instead of 5. To find it, look for the left-aligned value in the column, or compare the cells with the count. Then convert it to a number by retyping the value or reformatting the cell, and the SUM and the COUNT will both update.
Exercise
A list occupies B2:B6, and the total is =SUM(B2:B6) in B7. You click on row 7 and insert a new row above it, then type a value in the new B7. Is the new value included in the total? Why or why not?
Show answer
No. The new row sits directly below the last row of the range, so it is outside B2:B6. The total moves down to B8 and still reads =SUM(B2:B6). To include the new row, edit the range to B2:B7, or build the original formula with a range that already covers the empty space, such as B2:B100, with the total placed outside it.