Sub topic 13
Charts and slicers for pivot tables
This chapter assumes you can build a pivot table with rows, columns, values and a filter, and that you know how Summarize by and sorting work. Here you will chart a pivot table, add slicers to filter it, and learn where the pieces stop behaving the way you expect.
How the pieces connect
A chart built from a pivot table reads the pivot table's output range, not the source data. A slicer works one step earlier. It filters the source rows, and the pivot table recalculates from what is left. The chart then redraws from the new pivot output.
This order explains most surprises. The chart changes whenever the pivot layout changes, and a slicer only matters if its data range matches the pivot's source.
Creating a chart from a pivot table
- Click any cell inside the pivot table.
- Choose Insert > Chart.
- Sheets proposes a chart type in the chart editor. Change it under Setup > Chart type if it does not fit the question.
The editor's data range now points at the pivot table's output cells. If you add a field to Rows or Columns, the chart updates without any editing. This is the main benefit of charting a pivot table. You can restructure the summary and the chart follows.
Choosing a chart type that fits the layout
The shape of the pivot table decides which chart types make sense.
| Pivot layout | Good chart | Reason |
|---|---|---|
| One row field, one value | Column or bar chart | One bar per row item |
| One row field, one value, row items are dates | Line chart | Dates read as a trend |
| One row field, one column field, one value | Stacked or grouped column | Each column item becomes a series |
| One row field, share of total (Show as) | Pie or stacked bar | Values already sum to 100% |
| Many row items (more than about 12) | Sorted bar chart | Pie slices become unreadable |
Sort the pivot table before you chart it. A bar chart of regions sorted by revenue descending is far easier to read than the same chart in alphabetical order. The chart inherits the pivot's row order, so the sort setting from the earlier chapter on sorting applies here directly.
What the chart does with totals
Pivot tables can show grand totals and subtotals. A total drawn as a bar next to its own parts distorts the picture. After you create the chart, check whether a "Grand Total" category appears. If it does, turn off Show totals for that field in the pivot editor. Doing this also keeps the chart honest if you later change the layout.
Rows, columns and series
When the pivot has both a row field and a column field, each column item becomes a series. A pivot with Region in Rows and Quarter in Columns produces one series per quarter, with regions along the axis. If you wanted one series per region instead, use Setup > Switch rows / columns in the chart editor, or swap the fields in the pivot table. Swapping in the pivot is usually better, because the table and the chart then stay consistent.
Also check Use row 1 as headers and Use column A as labels in the chart editor. A pivot table normally needs both on. If a column header shows up as a data point or the first category disappears, one of these is off.
Adding a slicer
A slicer is a filter control that sits on the sheet. Anyone viewing the sheet can click it, so it suits dashboards.
- Select a cell in the pivot table.
- Choose Data > Add a slicer.
- In the slicer panel, open Data and check the Data range. It should be the same range the pivot table uses as its source, for example
Sales!A1:E. - Set Column to the field you want to filter on, such as Region.
- Click the slicer on the sheet, open its filter menu, and pick the values to keep.
The filter menu has two parts, Filter by condition and Filter by values. They behave as they do in a normal filter. For example, you can use the condition "Text contains" or untick individual values.
Slicers filter the source, not the pivot
A slicer on Region removes rows from the source data before aggregation. Consider a pivot with Product in Rows and Region not shown anywhere. A Region slicer still works, because it filters source rows and not pivot items. This is the practical difference from the pivot table's built-in filter:
| Row | Pivot editor filter | Slicer |
|---|---|---|
| Lives in | The pivot editor side panel | On the sheet, as a movable control |
| Field must be in the pivot | No, any source column can be filtered | No, any source column in its data range |
| Can control several pivots or charts | No, one pivot only | Yes, choose targets under **Apply to charts** or **Customize** |
| Intended user | Whoever builds the table | Whoever reads the sheet |
If both a pivot filter and a slicer are active, a row must pass both to be counted. When a pivot shows fewer rows than you expect, check both places.
One slicer, several targets
In the slicer panel, the Customize tab (or Apply to setting, depending on your version) lets you choose which charts and pivot tables the slicer controls. Tick every pivot you want the slicer to drive. A pivot is only affected if its source range matches the slicer's data range, so a pivot on Sales!A1:E and a pivot on Returns!A1:D cannot share one slicer.
Make sure the source ranges are identical, not merely overlapping. A slicer on Sales!A1:E100 will not control a pivot on Sales!A1:E. Using the open-ended form A1:E for every pivot and slicer avoids this, and it also covers new rows as the data grows.
Building a small dashboard
A reliable layout is the following:
- Keep source data on a
Salessheet. - Put the pivot table on a
Summarysheet, with its totals off if you plan to chart it. - Insert a chart from the pivot and move it next to the pivot.
- Add one slicer for Region and one for Product, both pointing at
Sales!A1:E. - Point both slicers at every pivot on the sheet.
Choosing a Region in the slicer now narrows the pivot, and the chart redraws.
When a pivot chart is the wrong tool
A chart on a pivot changes shape whenever someone changes the pivot. That helps when you explore data. It hurts in a shared report where the chart must keep its layout. Two cases come up often:
- Fixed categories. The pivot only lists items that exist in the filtered data, so a category with no rows vanishes from the chart. A formula table can keep a fixed list.
- Top N charts. A pivot can limit rows only through sorting and manual filtering. A QUERY can do it directly.
For a chart that stays put, build the chart on a formula-driven range instead:
=QUERY(Sales!A1:E, "select B, sum(E) where B is not null group by B order by sum(E) desc limit 5 label sum(E) 'Total revenue'", 1)This returns the five regions with the highest revenue, sorted, with a clear header. Chart that range. Slicers do not filter QUERY results unless the slicer targets the range inside the formula. For this reason, many dashboards use a pivot table for interactive exploration and QUERY for fixed reports.
If a chart needs single values from a pivot, you can read them with GETPIVOTDATA. For example, =GETPIVOTDATA("Revenue", Pivot!A1, "Region", "West") stays correct even if the pivot's layout moves. Charting a column of such formulas decouples the chart from the pivot's layout.
Common problems
- The chart shows a "Grand Total" bar. Turn off totals for the pivot's row or column field.
- A slicer does nothing. Compare its data range to the pivot's source range character by character. Then confirm the pivot is ticked as a target.
- The chart has too many series. A column field with many unique values makes one series for each. Remove the column field or filter it.
- New rows do not appear. The pivot's source range is fixed and too short. Extend it, or use an open-ended range such as
A1:E. - The chart axis labels are numbers, not text. Use column A as labels and make sure the row field is not formatted as a number.
Exercise
A pivot table on Sales!A1:E has Region in Rows and Revenue summed in Values. You add a Region slicer whose data range is Sales!A1:E100. Selecting "West" in the slicer changes nothing. Give two likely causes and a fix.
Show answer
The slicer's data range (A1:E100) does not match the pivot's source range (A1:E), so the slicer does not control that pivot. Also, the pivot may not be ticked as a target in the slicer's settings. Fix it by setting the slicer's data range to Sales!A1:E and making sure the pivot table is selected as a target.
Exercise
You chart a pivot table with Region in Rows, Quarter in Columns and Revenue in Values. The chart has one series per quarter, but you want one series per region. How can you change this, and which method is better?
Show answer
Use Switch rows / columns in the chart editor, or swap Region and Quarter in the pivot editor. Swapping in the pivot is better because the table and the chart then stay consistent.
Exercise
A manager wants a chart that always shows the top 5 products by revenue, even as the data changes. Why is a chart on a pivot table a weaker choice than a chart on a QUERY result, and what would the QUERY clause look like?
Show answer
A pivot cannot limit itself to the top 5 automatically, so its rows and chart change with the data and filters. A QUERY can use order by sum(E) desc limit 5 to return exactly five sorted rows, which you can chart directly.