You can create a PivotTable either from a database table or from a range of data. If you have a database table already, as in the example, you can create the PivotTable from that. Otherwise, create the database table you'll use, or enter the data in a worksheet as usual without creating a database table.
Once your data is ready, you can create a PivotTable either automatically or manually. Which works best depends on your data and what you're trying to do with it, but often you can save time by creating a PivotTable automatically and then adjusting it as necessary. If an automatic PivotTable turns out not to be what you need, you can create the PivotTable manually from scratch instead.
To create a PivotTable automatically, follow these steps:
Figure 12–2 shows the automatic PivotTable produced from the sample data table, with the PivotTable Builder window positioned in front of the worksheet.
Figure 12–2. The quickest way to create a PivotTable is to have Excel create it automatically. You will usually need to adjust the PivotTable using the PivotTable Builder window to make the PivotTable show the information you want. Depending on the data you're using, the PivotTable may look substantially different from this one.
After creating a PivotTable automatically, you'll normally need to adjust it. This is because Excel seldom guesses exactly which information you need where.
To adjust a PivotTable, use the techniques you'll learn in the next section, which shows you how to build a PivotTable from scratch.
If creating an automatic PivotTable doesn't give a useful result or if you prefer to do things by hand, you can build the PivotTable manually using the PivotTable Builder.
To create a PivotTable manually, follow these steps:
Figure 12–3. In the Create PivotTable dialog box, choose the table or range of data from which to create the PivotTable. Then choose between putting the PivotTable on a new worksheet or an existing worksheet.
NOTE: Instead of creating a PivotTable from data in a worksheet, you can create a PivotTable from an external data source such as a FileMaker database or Access database. To do so, you select the Use an external data source option button in the Choose the data that you want to analyze area of the Create PivotTable dialog box, click the Get Data button, then choose the data source. Before you can do this, you must install an Open Database Connectivity (ODBC) driver to enable Excel to connect to the data source, as discussed in Chapter 10.
Figure 12–4. When you insert a PivotTable manually, Excel creates an empty framework on which you lay out the PivotTable the way you need it.
Now that you've inserted the framework for the PivotTable, you can add fields to it from the Field name list box in the PivotTable Builder window.
Take a moment to look at the PivotTable framework and the PivotTable Builder window. You use the PivotTable Builder window to arrange the fields on the PivotTable framework.
Here are the essentials you need to know:
NOTE: Excel automatically parses the fields in the Field name list box and decides which part of the PivotTable they belong to. Given that Excel has no understanding of what your data table or range contains beyond being able to identify items such as dates, currency, and text, it's pretty smart about this. But you'll often need to move a field from one part of the PivotTable to another by dragging it from one area of the PivotTable Builder window to another.
If this is hard to grasp, don't worry. You'll see how PivotTables work in just a moment.
To create the PivotTable, you add fields to the PivotTable framework by dragging fields to the Report Filter box, the Row Labels box, the Column Labels box, and the Values box in the PivotTable Builder window.
NOTE: You can also add fields by selecting their check boxes in the Field name list box. When you select a field, Excel places it automatically depending on what its contents appear to be. Because Excel doesn't know what your data represents and what you're trying to show, it often puts the field in the wrong place. So it's usually best to place the fields yourself by dragging them.
Which fields you need to drag where depends on your data source and what you're trying to make it show. Here's a walk-through using the fields in the data source. If you're using the sample data source, your results should look similar; if your data source is different, they'll look different, but the PivotTable will work in much the same way.
In the Field name list box in the PivotTable Builder window, click the Year field and drag it to the Report Filter box. Excel selects the Year check box, enters Year in cell A1, and creates a pop-up menu for selecting the years in cell B1 (see Figure 12–5).
Figure 12–5. Drag the Year button from the Field name box in the PivotTable Builder window to the Report Filter box to create the Year pop-up menu shown in cell B1 here. Excel selects the (All) item in the pop-up menu at first, making the PivotTable show all the years.
Figure 12–6. Moving the Salesperson button to the Row Labels box makes Excel create a row label from each salesperson's name.
Figure 12–7. Drag the Line item from the Field name list box in the PivotTable Builder window to the Column Labels area. Excel adds the product lines as column labels and selects the Line check box for you.
Figure 12–8. Drag the Total Price field from the Field name list box to the Values box in the PivotTable Builder window to add the totals of each salesperson's sales to the PivotTable.
This gives us a PivotTable that shows how much of each product line each salesperson sold. At first, the PivotTable shows (All) in the Year pop-up menu in the Report Filter area. To see a breakdown by a year, open the Year pop-up menu,then click the year you want.
This is useful—but it's just the start of what you can do with the PivotTable.
The great thing about PivotTables is how easy they are to change to show different data. You can change a PivotTable by adding different fields to it, removing fields it's currently using, or rearranging the fields among the Report Filter box, the Column Labels box, the Row Labels box, and the Values box in the PivotTable Builder window.
Here are four examples of how you can change the basic PivotTable created earlier in this chapter. These examples work as a sequence, so you'll need to make each change in turn if you want to work through them.
Figure 12–9. Drag the Product field to the Row Labels box in the PivotTable Builder window to add a list of the products each salesperson has sold. You can collapse any list by clicking the disclosure triangle to the left of the salesperson's name.
Figure 12–10. Drag the Salesperson field below the Product field in the Row Labels box in the PivotTable Builder window to produce a list of products showing the salespeople who have been selling them.
Figure 12–11. Removing the product lines and making column labels of the products produces this PivotTable that shows how much each salesperson has sold of each product.
Figure 12–12. You can add the Month field to the Report Filter box, putting it below the Year field, to filter your PivotTable by first the year (here, 2011) and then the month (here, January). This PivotTable shows how much customers bought from each product line in January 2011.
When you've finished working with the PivotTable Builder window, you can close it by clicking the Close (x) button at the left end of its title bar or by choosing PivotTable View Builder from the Ribbon.
If you need to open the PivotTable Builder window again, choose PivotTable View Builder from the Ribbon.
When you add values to a PivotTable, Excel tries to automatically use the right function for the calculation that type of data needs. For example, when you add a field that shows prices, Excel uses the SUM() function on the assumption that you want to add the values. And if you use nonnumeric data such as names, Excel uses the COUNT() function, giving you the number of different items.
If you need to change a field to a different function, follow these steps:
Click the field, or click a cell containing data that the field produces.
TIP: You can also open the PivotTable Field dialog box for a field by clicking the i button to the right of the field's name in the PivotTable Builder window.
Figure 12–13. In the PivotTable Field dialog box, you can change the formula used to summarize the field's data.
TIP: If you need to present the data in a different format (for example, as the amount of difference from a base value), click the Options button in the PivotTable Field dialog box to expand the dialog box and reveal more options. In the Show data as pop-up menu, choose the format you want—for example, Difference From. Then select the base field in the Base field list box and the base item in the Base item list box.
3.147.72.74