IN THIS CHAPTER
The pivot table feature is perhaps the most technologically sophisticated component in Excel. With only a few mouse clicks, you can slice and dice a data table in dozens of different ways and produce just about any type of summary you can think of.
If you haven't yet discovered the power of pivot tables, this chapter provides an introduction, and Chapter 34, “Analyzing Data with Pivot Tables,” continues with many examples that demonstrate how easy it is to create powerful data summaries using pivot tables.
A pivot table is essentially a dynamic summary report generated from a database. The database can reside in a worksheet (in the form of a table) or in an external data file. A pivot table can help transform endless rows and columns of numbers into a meaningful presentation of the data — and do it so quickly you'll be amazed.
For example, a pivot table can create frequency distributions and cross-tabulations of several different data dimensions. In addition, you can display subtotals and any level of detail that you want.
Perhaps the most innovative aspect of a pivot table is its interactivity. After you create a pivot table, you can rearrange the information in almost any way imaginable and even insert special formulas that perform new calculations. You even can create post hoc groupings of summary items (for example, combine Northern Region totals with Western Region totals). And the icing on the cake: with a few mouse clicks, you can apply formatting to a pivot table to convert it into an attractive report.
One minor drawback to using a pivot table is that, unlike a formula-based summary report, a pivot table does not update automatically when you change information in the source data. This drawback doesn't pose a serious problem, however, because a single click of the Refresh button forces a pivot table to update itself with the latest data.
Pivot tables were introduced in Excel 97, and this feature improves with every new version of Excel. Unfortunately, many users avoid this feature because they think it's too complicated. My goal in this chapter is to dispel that myth.
The best way to understand the concept of a pivot table is to see one. Start with Figure 33.1, which shows a portion of the data used in creating the pivot table in this chapter. This range happens to be in a table (created by using Insert Tables Table), but that's not a requirement for creating a pivot table.
This table consists of a month's worth of new account information for a three-branch bank. The table contains 712 rows, and each row represents a new account opened at the bank. The table has the following columns:
The bank accounts database contains quite a bit of information. In its current form, though, the data doesn't reveal much. To make the data more useful, you need to summarize it. Summarizing a database is essentially the process of answering questions about the data. Following are a few questions that may be of interest to the bank's management:
You can, of course, spend time sorting the data and creating formulas to answer these questions. But almost always, a pivot table is a better choice. Creating a pivot table takes only a few seconds, doesn't require a single formula, and produces a nice-looking report. In addition, pivot tables are much less prone to error than creating formulas.
Later in this chapter, you'll see several pivot tables that answer the preceding questions.
Figure 33.2 shows a pivot table created from the bank data. This pivot table shows the amount of new deposits, broken down by branch and account type. This particular summary is one of dozens of summaries that you can produce from this data.
Figure 33.3 shows another pivot table generated from the bank data. This pivot table uses a drop-down Report Filter for the Customer item (in row 2). In the figure, the pivot table displays the data only for existing customers. (The user can also select New or All from the drop-down control.)
Notice the change in the orientation of the table? For this pivot table, branches appear as column labels, and account types appear as row labels. This change, which took about five seconds to make, is another example of the flexibility of a pivot table.
A pivot table requires that your data be in the form of a rectangular database table. You can store the database in either a worksheet range (which can be a table or just a normal range) or an external database file. And although Excel can generate a pivot table from any database, not all databases benefit.
Generally speaking, fields in a database table consist of two types of information:
A single database table can have any number of data fields and category fields. When you create a pivot table, you usually want to summarize one or more of the data fields. Conversely, the values in the category fields appear in the pivot table as rows, columns, or filters.
Exceptions exist, however, and you may find the Excel PivotTable feature useful even for databases that don't contain actual numerical data fields.
Figure 33.4 shows an example of an Excel range that is not appropriate for a pivot table. You might recognize this data from the outline example in Chapter 27, “Creating and Using Worksheet Outlines.” Although the range contains descriptive information about each value, it does not consist of normalized data. In fact, this range actually resembles a pivot table summary, but it's much less flexible.
Figure 33.5 shows the same data, but normalized. This range contains 78 rows of data — one for each of the six monthly sales values for the 13 states. Notice that each row contains category information for the sales value. This table is an ideal candidate for a pivot table and contains all information necessary to summarize the information by region or quarter.
Figure 33.6 shows a pivot table created from the normalized data. As you can see, it's virtually identical to the nonnormalized data shown in Figure 33.4. Working with normalized data provides ultimate flexibility in designing reports.
How easy is it to create a pivot table? This task requires practically no effort if your data is appropriate and you choose a Recommended PivotTable.
If your data is in a worksheet, select any cell within the data range and choose Insert Tables Recommended PivotTables. Excel quickly scans your data, and the Recommended PivotTables dialog box presents thumbnails that depict some pivot tables that you can choose from. Figure 33.7 shows the Recommended PivotTables dialog box for the bank account data.
The pivot table thumbnails use your actual data, and there's a good chance that one of them will be exactly what you're looking for — or at least close to what you're looking for. Select a thumbnail, click OK, and Excel creates the pivot table on a new worksheet.
When any cell in a pivot table is selected, Excel displays the PivotTable Fields task pane. You can use this task pane to make changes to the layout of the pivot table.
If none of the Recommended PivotTables is suitable, you have two choices:
In this section, I describe the basic steps required to create a pivot table, using the bank account data described earlier in this chapter. Creating a pivot table is an interactive process. It's not at all uncommon to experiment with various layouts until you find one that you're satisfied with. If you're unfamiliar with the elements of a pivot table, see the sidebar “Pivot Table Terminology.”
If your data is in a worksheet range, select any cell in that range and then choose Insert Tables PivotTable. The Create PivotTable dialog box, shown in Figure 33.8, appears.
Excel attempts to guess the range, based on the location of the active cell. If you're creating a pivot table from an external data source, you need to select that option and then click Choose Connection to specify the data source.
Use the bottom section of the Create PivotTable dialog box to indicate the location for your pivot table. The default location is on a new worksheet, but you can specify any range on any worksheet, including the worksheet that contains the data.
Click OK, and Excel creates an empty pivot table and displays a PivotTable Fields task pane, as shown in Figure 33.9.
Next, set up the actual layout of the pivot table. You can do so by using of the following techniques:
The following steps create the pivot table presented earlier in this chapter (see “A pivot table example”). For this example, I drag the items from the top of the PivotTable Fields task pane to the areas in the bottom of the PivotTable Fields task pane.
Figure 33.10 shows the completed pivot table.
By default, pivot tables use General number formatting. To change the number format for all data, right-click any value and choose Number Format from the shortcut menu. Then use the Format Cells dialog box to change the number format for the displayed data.
You can apply any of several built-in styles to a pivot table. Select any cell in the pivot table and then choose PivotTable Tools Design PivotTable Styles to select a style. Fine-tune the display by using the controls in the PivotTable Tools Design PivotTable Style Options group.
You can also use the controls from the PivotTable Design Layout group to control various elements in the pivot table. You can adjust any of the following elements:
The PivotTable Tools Analyze Show group contains additional options that affect the appearance of your pivot table. For example, you use the Show Field Headers button to toggle the display of the field headings.
Still more pivot table options are available from the PivotTable Options dialog box. To display this dialog box, choose PivotTable Tools Analyze PivotTable Options. Or right-click any cell in the pivot table and choose PivotTable Options from the shortcut menu.
The best way to become familiar with all these layout and formatting options is to experiment.
After you create a pivot table, changing it is easy. For example, you can add further summary information by using the PivotTable Fields task pane. Figure 33.11 shows the pivot table after I dragged a second field (OpenedBy) to the Rows section in the PivotTable Fields task pane.
Here are some tips on other pivot table modifications you can make:
To demonstrate the flexibility of this feature, I created some additional pivot tables. The examples use the bank account data and answer the questions posed earlier in this chapter. (See “A pivot table example.”)
Figure 33.13 shows the pivot table that answers this question.
Sum
.Note that the pivot table can also be sorted by any column. For example, you can sort the Grand Total column in descending order to find out which day of the month had the largest amount of new funds. To sort, just right-click any cell in the column to sort and choose Sort from the shortcut menu.
Figure 33.14 shows the pivot table that answers this question.
Sum
.I added conditional formatting data bars to make it easier to see how the days compare. As you see, the largest deposit days are Fridays.
Figure 33.15 shows a pivot table that answers this question.
Count
.So far, all the pivot table examples have used the Sum
summary function. In this case, I changed the summary function to Count
. To change the summary function to Count
, right-click any cell in the Values area and choose Summarize Values By Count from the shortcut menu.
Figure 33.16 shows a pivot table that answers this question. For example, 253 (or 35.53%) of the new accounts were for an amount of $5,000 or less.
This pivot table is unusual because it uses only one field: Amount.
Count
.Count
and summarized by Percent of Column Total
.When I initially added the Amount field to the Rows section, the pivot table showed a row for each unique dollar amount. To group the values, I right-clicked one of the Row labels and chose Group from the shortcut menu. Then I used the Grouping dialog box to set up bins of $5,000 increments. Note that the Grouping dialog box does not appear if you select more than one Row label.
The second instance of the Amount field (in the Values section) is summarized by Count
. I right-clicked a value and chose Summarize Data By Count from the shortcut menu.
I added another instance of Amount to the Values section, and I set it up to display the percentage. I right-clicked a value in column C and chose Show Values As % of Column Total. This option is also available in the Show Values As tab of the Value Field Settings dialog box.
The pivot table in Figure 33.17 shows that the most common account opened by tellers is a checking account.
Count
).% of Column Total
).This pivot table uses the OpenedBy field as a filter and is showing the data only for tellers. I sorted the rows so that the largest value is at the top, and I used conditional formatting to display data bars for the percentages.
Figure 33.18 shows a pivot table that answers this question. At the Central branch, tellers opened 23 checking accounts for new customers.
Count
.This pivot table uses three Report Filters. The Customer field is filtered to show only New, the OpenedBy field is filtered to show only Teller, and the AcctType field is filtered to show only Checking.
The examples in this chapter should give you an appreciation for the power and flexibility of Excel pivot tables. The next chapter digs a bit deeper and covers some advanced features — with lots of examples.