A fantastic question came up during last week’s open lab. Is it possible to create a PivotChart pie chart that can be filtered to show only the percent of the item selected? Here is one solution for that question (and spoiler alert, it is technically not a PivotChart).
A few things before we get started…
- First, thank you to Marsha for having this question and inspiring this Byte!
- Second, this article assumes you have some knowledge of Tables, PivotTables, and Charts in Excel. If you don’t, please come attend a session… times are listed in myTraining.
- Lastly, this is basically a different take on the idea of a progress pie chart… and I am by no means the creative genius behind this overall idea! If you have a minute, look at some of the tutorials out there for the different use cases for these. They are mighty handy.
Normally when you select a slicer or filter a Pie chart by one item, each item shows as 100%. Here is an example:
Below is a visual of a PivotChart Pie Chart…
Looks great… but when I add my slicers and filter by one item, it always shows as 100% of the total, because it is 100% of what is displayed.
What if we want to use those slicers, but also maintain the visual of the item’s percent of the grand total… in other words, in this case, to still show as 36% of the whole? Some finagling is in order.
Rather than an exercise, I am going to try something different. Here is the final document… and below will be the steps I took to create it: Example Document
In the document, one sheet is the source data, and the other sheet is the final chart with slicers that will adjust the pie chart accordingly.
Click on a few slicer buttons to test it out. Pretty cool!
We originally started with source data (on the Source Data sheet in the document) that consisted of two columns: item and a number.
Format as a Table
This first step might be optional, depending on your use case. Since data would be fluctuating in our case (e.g. new rows of data added), it was best to format as a table.
We learn about tables in Excel Essentials, and the advantages of formatting as tables in Excel Pivot Tables, so please come to a session if you are interested in learning more!
1. You can either go to the Home tab, Format as Table, or use the command Ctrl + T.
2. Pick a design if you would like (in this case, yellow for WSU).
Create a Helper Column for Percent
We need a cheat column that would keep a percent constant when filtered, so a helper column was in order. You have probably noticed that formulas look different in a table… you still want to build them in the first cell of a column to carry them down.
We want the column to take the figures in column B and divide them by the total. The formula ends up looking like this: =[@Number]/SUM([Number])
This looks complicated, but it is very automatic. Here were my keystrokes/mouse clicks:
[click into the first cell of Column C], Type = [click on B1] / SUM [Select B2 through B7].
Create a Pivot Table
- Click on the table to activate Table Design tab.
- On Table Design tab, Select Summarize with PivotTable.
- Location of Pivot Table: on a new sheet, titled Pivot.
- Build the table with Item as rows, Helper Column as Values.5. Insert Slicer for Item (on the PivotTable Analyze tab).
Create Helper Cells with GETPIVOTDATA
So here is the twist… Instead of creating a PivotChart, we are actually going to create a chart from helper cells that reference information from the PivotTable.
1. The first helper cell references the Grand Total of the PivotTable:
[Click in B1], type = [click on the Grand Total cell of the PivotTable].
Notice how this appears in the formula bar as a GETPIVOTDATA formula in the formula bar. This cell will always return whatever Pivot Grand Total is Displayed.
2. The second helper cell, in B2, contains the formula =1-B1. So it will always read the difference of 100% from whatever the GETPIVOTDATA result shows.
Create Chart from Helper Cells
Finally, we can make the chart!
1. Select the two Helper Cells in B1 and B2.
2. Go to the Insert tab, and select the Pie Chart dropdown.
3. Select the Doughnut (it could be any of the pies, but this is the route I took for reasons you will see).
4. If desired, you can pick special colors by right clicking on any data point and selecting Fill. I picked some WSU colors.
The number you see in the center of the doughnut is actually a title. Remember how we learn in Excel Pivot Tables, Charts and Pictures training that a chart title can reference a specific cell? This will come in handy here.
1. Title: Click on the line of the title and press = , then click on B1
So this Title will always reference this cell, which will always reference the grand total displayed on the PivotTable.
This means you will always have a number corresponding to the colors on the chart.
2. Text Box: This may be optional depending on your situation, but I inserted a Text Box at the top of the chart to read Percent of Total: Insert tab, Text Box.
3. Position Slicers: Final step was moving the Slicers and resizing them so they fit neatly on top of the Pivot Table. This was only cosmetic, and is also optional. Really there are infinite possibilities for how you could play around with final formatting with a chart like this.
A Simple Alternative
It is worth mentioning that, depending on your situation, you may be able to skip the PivotTable step by incorporating a total row in your Table. This would apply if you didn’t need to sum multiple entries of specific items.
You would still need to incorporate helper columns, but instead of linking to the Grand Total of the PivotTable, they could link to the Total Row sum.
So many possibilities!
What do you think? Has this sparked any ideas? Have you used pie/doughnut charts for this type of scenario before?
Congratulations, Power Users!
Congratulations to our newest Power Users! For the full gallery, and more information about the WSU Microsoft Office Power User Program, please visit: wichita.edu/poweruser
Megan Nold (not pictured)