Microsoft Excel provides a very flexible tool to arrange summaries of data, called the Pivot Table. The possibilities to look at data from different angles offered by a PivotTable go well beyond this introduction. Go ahead and explore!
We will use the Employees worksheet in the Intro to Excel workbook to demonstrate PivotTables. Let’s say we wanted to count how many males and how many females there are in the data set and arrange that information in the following tabular format (called a “frequency distribution” in statistics):
Table 5‑1
Gender |
Count |
Female |
7 |
Male |
18 |
Total |
25 |
To construct such a frequency distribution proceed as follows:
The pivot table wizard leads you through the creation of a pivot table in four steps.
Figure 5‑1
Note: Make sure that this range includes a label for this variable in the first row of the selected range (A1 in our case) since you will need to use that label to construct the pivot table.
Figure 5‑2
Figure 5‑3
Excel will create a new worksheet with the “skeleton” of a PivotTable and you will see the PivotTable toolbar and the PivotTable Field List window as shown in the following Figure.
Figure 5‑4
A PivotTable basically has four components:
The PivotTable toolbar contains a variety of formatting and functional. The PivotTable Field List window contains objects that refer to ranges selected in Step 2 of the wizard. In our example, the only range is represented by the “GENDER” field object (“button”). You build a PivotTable by dragging the field objects from the PivotTable Field List window to the appropriate areas of the PivotTable outline.
Figure 5‑5
As soon as you drop the GENDER button onto the Data Items area, Excel creates the PivotTable which should look as follows:
Figure 5‑6
As mentioned before, the power of PivotTables comes from the opportunity to quickly change the layout of the table. For example, drag the GENDER button from A4 to B3 (which basically drags the Gender field from the “Row Fields Area” to the “Column Fields Area”). Your PivotTable now looks like this:
Figure 5‑7
Not that impressive yet, but wait …
Let’s drag the GENDER button back to A4 to go back to the original row-wise layout. Let’s say we wanted to express the frequency count as percentages rather than absolute numbers.
Figure 5‑8
Figure 5‑9
The PivotTable now shows the distribution of males and females as percentages (or “relative frequencies”) as shown in the following figure.
Figure 5‑10
What if we wanted to summarize the salary information such that we group our 25 employees into 6 groups covering a salary range of $5,000 each as shown in the following table?
Table 5‑2
Salary Between |
Count |
20 < 25 |
2 |
25 < 30 |
6 |
30 < 35 |
8 |
35 < 40 |
5 |
40 < 45 |
3 |
45 < 50 |
1 |
Figure 5‑11
Figure 5‑12
Figure 5‑13
Figure 5‑14
Figure 5‑15
You will see that the pivot table produced so far doesn’t look anything like the desired frequency distribution for SALARY (see the following figure). That’s because none of the data are grouped into categories of our choice. In fact, we couldn’t even tell Excel what our choices for these groupings are, yet.
Figure 5‑16
To group the data items:
Figure 5‑17
Figure 5‑18
The grouped frequency distribution is now complete and should look like this:
Figure 5‑19
OK, let’s get a bit more sophisticated. What if we wanted to generate a table that shows the number of employees as a function of gender and as a function of how many people live in their household. Statisticians call this a “joint frequency distribution” or “crosstab.”
Figure 5‑20
Figure 5‑21
This will give us a two-dimensional frequency distribution about how many employees fall into each of the 10 cells that combine information about GENDER and HOUSEHOLD size. See the following figure.
Figure 5‑22
You can easily change the layout of this table by dragging either the GENDER button or the HOUSEHOLD button onto different areas of the PivotTable. You can also generate a Page Field by dragging one of these buttons over the top of the pivot table. The result is a field that allows you to choose a basis for the PivotTable.
Figure 5‑23
Figure 5‑24
Your PivotTable now only gives the distribution of the household sizes for the 18 males in our data set (see the following Figure).
Figure 5‑25
Figure 5‑26
Figure 5‑27
Your PivotTable now shows average salaries in addition to the count of employees for each cell (see the following figure).
Figure 5‑28
Use the Top Web Sites worksheet in your Intro to Excel workbook.
1) Use a PivotTable to find the average number of users for each web site category.
2) Use a page field to show the average number of users for web sites from the Finance category only.