Sub topic 15
Charting a PivotTable with a PivotChart
This chapter assumes you can build a PivotTable with fields in the Rows, Columns and Values areas, and that you know how to sort and filter its results. If you can already produce the Region by Product grid of total sales, you have what you need.
What a PivotChart is
A PivotChart is a chart that is bound to a PivotTable. It does not read cells directly. It reads the PivotTable's current layout, so the two always describe the same data. If you move a field in one, the other changes with it.
This differs from a normal chart drawn over the PivotTable's cells. A normal chart holds a fixed range. When the PivotTable grows, shrinks or reorders, that range can point at the wrong cells. A PivotChart follows the PivotTable's structure and avoids that problem.
The mapping between the two is fixed:
| PivotTable area | PivotChart area | Effect on the chart |
|---|---|---|
| Rows | Axis (Categories) | One group of bars or points per row item |
| Columns | Legend (Series) | One series (colour) per column item |
| Values | Values | The bar heights or point positions |
| Filters | Filters | Limits the data, not shown on the chart |
Creating a PivotChart
Use the sample data from earlier chapters, with the PivotTable laid out as follows.
Rows: Region
Columns: Product
Values: Sum of SalesThere are two ways to create the chart.
- Click any cell inside the PivotTable. On the PivotTable Analyze tab, choose PivotChart. Pick a chart type and select OK.
- Click inside the PivotTable and press Alt+F1 on Windows to insert a default clustered column chart on the same sheet. Press F11 to put the chart on its own chart sheet.
You can also use Insert > PivotChart to create a PivotTable and a PivotChart in one step, starting from the source range or Table. This is convenient, but you then lay out the fields through the same Fields pane.
With the sample data, Region becomes the horizontal axis. Widget and Gadget become two series, and each bar shows summed sales.
Working with the chart's field buttons
A new PivotChart shows grey field buttons on the chart. These let you filter and sort directly on the chart. For example, the Region button opens a menu with the same sort and filter options as the PivotTable's row field.
Changes made through the buttons change the PivotTable too. This surprises many users: filtering the chart to East removes West from the PivotTable as well.
To hide the buttons for a cleaner chart, right-click a button and choose Hide All Field Buttons on Chart. You can also use PivotChart Analyze > Field Buttons. Hiding them does not remove any filter that is already applied.
Choosing a chart type
Pick the chart type for the question you are answering, not for appearance.
- Clustered column or bar. Compares values across categories, or across series within each category. This is the right default for Region by Product.
- Stacked column. Shows the total for each category and how it splits across series. Individual segments are harder to compare, except for the one on the baseline.
- 100% stacked column. Shows each category's mix as a share of its own total. Use it with raw sums when you care about proportions.
- Line. Suits a date field on the axis, such as months after grouping dates.
- Pie. Works for a single series only, with few categories.
Some chart types are not available for PivotCharts. XY (scatter), bubble and stock charts cannot be used because they need a different data structure. Excel disables them in the chart type dialog.
Showing a trend over time
A PivotChart is often used for a time series. Put the date field in Rows and group it by months and years, as described in the grouping chapter. Then create a line chart.
With the sample data, grouping Date by Months gives three categories: Jan, Feb and Mar. The Columns area can hold Region, which gives one line per region.
If you group by Months only and your data spans several years, January of each year is merged into one point. Group by both Years and Months to keep them separate.
Layout and formatting that persist
A PivotChart keeps the formatting you apply to it, such as colours, titles and axis scale, when you change the PivotTable. Whether it keeps formatting of individual data points depends on one setting.
- Right-click the chart and choose Format Chart Area, or open the PivotChart Analyze tab.
- In the PivotTable options, on the Layout & Format tab, check Preserve cell formatting on update.
For the chart, formatting of a series is retained as long as that series still exists. If you filter a series out and bring it back, Excel usually restores its format. If you rename or replace the field, the format is lost.
Fixed axis limits can cause a different problem. If you set a maximum of 400 and later refresh data that includes a value of 600, the bar is cut off. Set axis limits to Auto unless you have a reason to fix them.
Refreshing and sharing a chart
A PivotChart refreshes whenever its PivotTable does. Use Data > Refresh All, or run the macro from the refresh chapter.
Sub RefreshAllPivots()
ThisWorkbook.RefreshAll
End SubRefreshing can change the chart's size. If the chart resizes unexpectedly, right-click the chart, choose Format Chart Area, open Size & Properties and set Properties to Don't move or size with cells. Chart size is independent of the PivotTable's size, so this keeps the layout stable.
Combining PivotCharts with slicers
A slicer connected to a PivotTable also controls its PivotChart. You can connect one slicer to several PivotTables, and so to several charts, through Slicer > Report Connections. This builds a small dashboard where one click changes every chart.
Keep in mind that two PivotCharts built from the same PivotTable are tied to each other. Filtering one filters the other, because they share the one PivotTable. To make independent charts, create a separate PivotTable for each, or use a slicer connected to only some of them.
Limitations and common problems
- You cannot chart a PivotTable's grand totals. PivotCharts omit grand totals and subtotals. If you need a total bar, add a separate series in a regular chart range or reshape the data.
- Calculated fields work, but only as values. A calculated field such as AvgPrice (=Sales/Units) appears in the chart. Remember it is computed from the summed Sales and summed Units, not row by row.
- Only one layout is possible. Because the chart mirrors the PivotTable, you cannot show Sales for East in one chart and Units for West in the same chart without both being in the PivotTable.
- Multiple value fields create a Values series. If you add both Units and Sales to Values, the chart shows a Values field button and both measures appear as series. Their scales differ widely, so the smaller measure appears flat. Move one measure to a secondary axis through Format Data Series > Secondary Axis, or chart them separately.
- Chart disappears or shows an error. If the PivotTable is deleted, the PivotChart becomes a regular static chart with a fixed copy of its last values. It no longer updates and loses field buttons. Keep the PivotTable, even on a hidden sheet, if you need the chart to update.
- Blank or odd categories. Blank cells in the source data show as "(blank)" on the axis. Fix the source data or filter that item out.
Summary of the workflow
- Build and verify the PivotTable first. The chart can only be as correct as the table.
- Create the PivotChart from the PivotTable Analyze tab.
- Choose a chart type that matches the question.
- Hide field buttons and tidy titles, labels and axes.
- Connect slicers or timelines for interaction.
- Refresh after the source data changes.
Exercise
A PivotTable has Region in Rows, Product in Columns and Sum of Sales in Values. You create a PivotChart and then filter the chart to show only the East region using the Region field button. What happens to the PivotTable, and why?
Show answer
The PivotTable also shows only East. A PivotChart is bound to its PivotTable, so a filter applied through a chart field button is applied to the PivotTable's Region field. To avoid this, use a separate PivotTable for the second view.
Exercise
You add both Units and Sales to the Values area and the Units bars look almost flat. Give two ways to fix the chart.
Show answer
Move one measure to a secondary axis with Format Data Series > Secondary Axis, or show the two measures in separate charts built from separate PivotTables. Changing the chart type for one series, for example Sales as columns and Units as a line, also helps once the secondary axis is set.
Exercise
Why can a PivotChart of monthly sales mix up January of 2025 and January of 2026, and how do you prevent it?
Show answer
If the date field is grouped by Months only, all Januaries fall into one category. Group by both Years and Months so each year and month stays distinct.