Sub topic 8
Summaries: SUMIF, QUERY, and ARRAYFORMULA
This chapter assumes you can navigate Google Sheets, use ranges such as B2:B, and write simple formulas such as SUM and IF. It also assumes Gemini in Sheets is available in your account. Use Gemini to draft a formula, then check the formula yourself before relying on its result.
Summary formulas answer different questions:
| Formula | Best for | Typical result |
|---|---|---|
| `SUMIF` | Adding values that meet one condition | Total groceries |
| `QUERY` | Grouping, filtering, and labeling data | Total for every category |
| `ARRAYFORMULA` | Applying one calculation to many rows | Amount plus tax for each row |
SUMIF: one condition
Suppose your expense sheet uses these columns:
- Column A: Date
- Column B: Category
- Column C: Description
- Column D: Amount
- Column E: Paid By
To total all expenses in the Groceries category, ask Gemini:
In column H, create a formula that adds the amounts in D2:D when the category in B2:B is "Groceries". Explain the formula.A suitable result is:
=SUMIF(B2:B, "Groceries", D2:D)SUMIF checks the criteria range, B2:B, for the text Groceries. It adds the matching cells from the sum range, D2:D.
For a category named in another cell, such as H1, use:
=SUMIF(B2:B, H1, D2:D)This version is easier to reuse. Change H1 to Travel, and the result changes automatically.
QUERY: grouped summaries
QUERY is useful when you want one result for every category instead of one result for one category. It uses a query string, which is a text instruction describing which columns to select, filter, or group.
Ask Gemini:
Using A1:E, create a two-column summary grouped by Category in column B. Add the Amount from column D for each category. Treat row 1 as headers and label the total column Total.A suitable formula is:
=QUERY(A1:E, "select B, sum(D) where D is not null group by B label sum(D) 'Total'", 1)The final 1 tells Sheets that the first row contains headers. The query selects category B, calculates sum(D), ignores rows without an amount, and groups equal categories together.
QUERY returns a table that can grow as new rows are added. Confirm that the referenced columns contain consistent data. Text in an Amount column can prevent numeric values from being included correctly.
ARRAYFORMULA: calculate a whole column
ARRAYFORMULA applies one expression to a range of rows. For example, to calculate an amount including 10% tax in column F, ask Gemini:
In column F, add a formula that shows the Amount from column D plus 10% tax, and leave the cell blank when column D is empty.A suitable formula is:
=ARRAYFORMULA(IF(D2:D="", "", D2:D*1.1))IF checks whether each Amount cell is empty. Empty rows remain empty. Otherwise, each amount is multiplied by 1.1.
Place this formula in F2, then leave the remaining cells in column F empty. The array result needs room to expand. If another value already occupies a target cell, Sheets can show an expansion error.
Check and refine Gemini's formulas
Test a generated formula with a small known case:
- Groceries: 20
- Travel: 35
- Groceries: 10
SUMIF for Groceries should return 30. If an amount is 50, the tax formula should return 55.
Ask follow-up questions when needed:
Rewrite the formula so it ignores negative amounts.Then inspect the new condition and test it again. Gemini can misunderstand headers, ranges, text-formatted numbers, or the meaning of “total.” Manual checking remains part of the task.
Exercise
Which formula should you use to total Amount in D2:D for rows where Category in B2:B is "Travel", and what result should you expect if the matching amounts are 35 and 15?
Show answer
Use =SUMIF(B2:B, "Travel", D2:D). The expected result is 50.