Sub topic 16
Charts that follow filtered or formula-driven data
Assume you know how to select ranges, enter formulas, and insert a basic chart. This chapter shows how to make a chart update when the rows behind it change.
A chart can use either raw data or a formula-generated table. For reliable updates, create a clean summary table first, then chart that table. The chart follows changes to the formula result, such as new sales rows, changed filters, or different criteria.
Use a formula-driven summary table
Suppose your source data is in columns A:C:
| Product | Region | Sales |
|---|---|---|
| Pens | North | 120 |
A QUERY formula can select and group the rows you want. Enter this formula in an empty area, such as E1:
=QUERY(A1:C100, "select A, sum(C) where B = 'North' group by A label sum(C) 'Sales'", 1)This formula creates a two-column summary containing each product and its total North-region sales. The final 1 tells Sheets that the first source row contains headers.
Select a range that includes the formula output, such as E1:F100, and choose Insert > Chart. Sheets uses the first column as labels and the second column as the data series. When the source rows change, the QUERY result changes and the chart updates.
Filter rows before charting
Use FILTER when you want to keep matching rows rather than summarize them. For example:
=FILTER(A2:C100, B2:B100 = "North")This returns every North-region row. You can chart the returned table, but ensure the selected chart range includes enough rows for the result to grow. Blank rows in the range are normally ignored.
For a user-controlled filter, place the criterion in a cell such as H1 and refer to it in the formula:
=QUERY(A1:C100, "select A, sum(C) where B = '"&H1&"' group by A label sum(C) 'Sales'", 1)Changing H1 from North to South changes the summary and the chart.
Avoid common range problems
- Put the formula output in a separate area or tab. Do not place it inside the source range.
- Include the formula's header row in the chart range.
- Use a bounded range such as
A1:C1000instead of entire columns when performance matters. - Check the chart editor's Setup tab if the chart includes the wrong columns.
- If new output is not displayed, edit the chart's data range so it includes more rows.
- Keep one label column and one or more numeric series columns. Mixed text and numbers can confuse automatic chart detection.
Exercise
You have sales in A:C and want a chart showing totals for the region named in H1. Which formula should you use?
Show answer
Use =QUERY(A1:C100, "select A, sum(C) where B = '"&H1&"' group by A label sum(C) 'Sales'", 1), then chart the returned summary table.