Sub topic 7
Combining several ranges and values
This chapter assumes you can enter formulas in Google Sheets and read cell addresses such as B2. It also assumes you have used a range such as B2:B6 with SUM, AVERAGE, COUNT, MIN, and MAX. Here you will pass more than one input to those functions in a single call. You will also see how that changes what each function returns.
Why one function call can take many inputs
Each of the five functions accepts a list of arguments separated by commas. An argument can be any of these:
- A range, such as
B2:B6. - A single cell reference, such as
B2. - A literal number typed into the formula, such as
100.
You can mix these in any order. The function collects every numeric value from all the arguments and works on them as one pool.
=SUM(B2:B6, D2:D6, 100)This formula adds the numbers in B2:B6, the numbers in D2:D6, and the literal 100.
Use this when your data is not in one block. Examples are two separate columns, a few scattered cells, or a fixed adjustment such as an opening balance.
The sample data
The examples below use this layout. Column B has five numbers. Column D has three numbers and two blank cells.
| Row | B (Store 1) | D (Store 2) |
|---|---|---|
| 2 | 10 | 5 |
| 3 | 20 | 15 |
| 4 | 30 | 25 |
| 5 | 40 | (blank) |
| 6 | 50 | (blank) |
Column B sums to 150 and has 5 numbers. Column D sums to 45 and has 3 numbers.
How the pooling works
Every argument is scanned, and only numeric values go into the pool. The function then applies its rule to the whole pool.
Because there is one pool, the order of arguments does not matter for these five functions. =SUM(D2:D6, B2:B6) gives the same answer as =SUM(B2:B6, D2:D6).
Multiple arguments in each function
SUM
=SUM(B2:B6, D2:D6)This returns 195, which is 150 + 45.
Adding the literal gives a different result:
=SUM(B2:B6, D2:D6, 100)This returns 295.
You can also pick individual cells:
=SUM(B2, B4, B6)This returns 90, which is 10 + 30 + 50. For three cells this is fine. For many cells, a range is shorter and easier to audit.
An equivalent form uses the plus operator:
=SUM(B2:B6) + SUM(D2:D6)It gives the same 195. The single-call form is easier to extend, because you add one more argument instead of one more SUM(...) term.
COUNT
=COUNT(B2:B6, D2:D6)This returns 8. The five numbers in column B and the three in column D go into the pool, and the two blanks do not. A literal number also counts:
=COUNT(B2:B6, 7)This returns 6.
MIN and MAX
=MIN(B2:B6, D2:D6)
=MAX(B2:B6, D2:D6)These return 5 and 50. Literal values take part in the comparison:
=MAX(B2:B6, D2:D6, 60)
=MIN(B2:B6, 0)The first returns 60 and the second returns 0. A common use is setting a floor or a cap. For example, =MAX(B2:B6, 0) can never return less than 0.
AVERAGE
=AVERAGE(B2:B6, D2:D6)This returns 24.375, which is 195 divided by 8. It is the SUM of the pool divided by the COUNT of the pool. That relationship is why the two earlier functions matter here.
Pooled average versus average of averages
A frequent mistake is averaging two averages.
=AVERAGE(AVERAGE(B2:B6), AVERAGE(D2:D6))Column B averages 30 and column D averages 15, so this returns 22.5. The pooled version returned 24.375. The results differ because the two columns have different counts: 5 numbers against 3. The average of averages gives each column equal weight. The pooled average gives each number equal weight.
| Formula | Result | Each... has equal weight |
|---|---|---|
| `=AVERAGE(B2:B6, D2:D6)` | 24.375 | number |
| `=AVERAGE(AVERAGE(B2:B6), AVERAGE(D2:D6))` | 22.5 | column |
Which one is right depends on the question. To ask "what is the typical sale across all stores?", use the pooled version. To ask "what is the typical store?", the average of averages may fit. Decide before you write the formula.
Overlapping ranges count twice
The function does not remove duplicates. If two arguments cover the same cell, that cell enters the pool twice.
=SUM(B2:B6, B4:B6)This returns 270. The cells B4:B6 hold 30, 40, and 50, which total 120. They are counted once as part of B2:B6 and again as the second argument, so 150 + 120 = 270.
The same overlap inflates COUNT. =COUNT(B2:B6, B4:B6) returns 8, not 5. This kind of bug does not produce an error message, so the formula looks fine while the answer is wrong. When a total looks too high, check whether your ranges overlap.
Ranges on other sheets
Each argument can point to a different sheet. Put the sheet name and an exclamation mark before the range.
=SUM(Jan!B2:B6, Feb!B2:B6, Mar!B2:B6)This adds the same range from three monthly sheets. If a sheet name contains spaces, wrap it in single quotes: 'Q1 Sales'!B2:B6.
You can mix sheets and local ranges freely:
=SUM(B2:B6, Archive!B2:B6, 100)Blanks and text inside multiple arguments
The rules from the previous chapter still apply to each argument. In the sample data, D5 and D6 are blank, so they add nothing to the pool. A text value in a range is skipped in the same way. A formula like =SUM(B2:B6, D2:D6) keeps working if someone types "n/a" into D5, but it silently leaves out that row. If you suspect hidden gaps, compare counts:
=COUNT(B2:B6, D2:D6)If you expect 10 values and get 8, two cells are blank or hold text.
Choosing between one call and several
| Situation | Better choice |
|---|---|
| Data in two or three separate blocks, one answer wanted | One call with several ranges |
| Data in one contiguous block | One range |
| You need a result per block | One formula per block |
| A fixed amount is added to a total | A literal argument or `+ 100` |
| Blocks need different weights | Separate formulas, combined explicitly |
If a literal such as 100 appears in a formula, think about whether it should live in its own cell instead. A value in a labeled cell can be seen and changed without editing the formula. A literal hides inside the formula.
Common errors
- Using a colon instead of a comma between ranges.
=SUM(B2:B6:D2:D6)is not two ranges. Separate arguments with commas. - Leaving out the comma.
=SUM(B2:B6 D2:D6)is a parse error. - Mixing up the separator in a different locale. See the callout earlier in this chapter.
- Counting overlap twice. Covered above.
- Averaging averages by accident. Covered above.
Exercise
Using the sample data (B2:B6 holds 10, 20, 30, 40, 50 and D2:D6 holds 5, 15, 25 followed by two blank cells), what do these three formulas return? (a) =SUM(B2:B6, D2:D6, 100) (b) =AVERAGE(B2:B6, D2:D6) (c) =SUM(B2:B6, B4:B6)
Show answer
(a) 295, because 150 + 45 + 100. (b) 24.375, because the pooled sum 195 is divided by the 8 numbers in the pool; the two blank cells are not counted. (c) 270, because B4:B6 (30, 40, 50) is included twice, adding 120 to 150.
Exercise
Write a single formula that returns the largest value across B2:B6 and D2:D6, but never less than 100. What does it return for the sample data?
Show answer
=MAX(B2:B6, D2:D6, 100). The literal 100 is part of the pool, so the result can never be below 100. For the sample data the largest value is 50, so the formula returns 100.
Exercise
A colleague writes =AVERAGE(AVERAGE(B2:B6), AVERAGE(D2:D6)) and gets 22.5. You want the typical value across every number in both columns. Which formula should you use, and why does it give a different answer?
Show answer
Use =AVERAGE(B2:B6, D2:D6), which returns 24.375. It averages all 8 numbers equally. The colleague's formula gives each column equal weight, but column B has 5 numbers and column D has 3, so the results differ.