21.1. Summary Tables RevisitedWhen you analyze large amounts of data, you can look at the same information in many different ways. How you organize and group the data often determines whether you find or overlook important trends. Note: In Chapter 15, you saw how to tame large tables of data with features like grouping and outlining. Pivot tables offer another approachthey're a little more work to set up, but they give you much more flexibility in rearranging your tables and calculating different summary information on the fly. Consider the small table of information shown in Figure 211. This table lists all the customers of a small business, along with information about their gender, the city they live in, and their level of education. Looking at this table, an important question comes to mind: is there a relationship between these different pieces of information and the amount of money a customer spends?
To look for trends and patterns in the customer list, it helps to build a summary table a table that tallies key amounts, like the average amount spent for a customer in a specific city, education level, or gender. However, there are several potentially important relationships, and, therefore, several types of summary tables that you could create. Pivot tables are the perfect summarybuilding tool because they give you almost unlimited flexibility when you want to figure out different relationships. But before you learn about how to build pivot tables, it first helps to understand what life is like in Excel without thembecause only then can you see why pivot tables make sense and decide whether you need them in one of your own workbooks. 21.1.1. Life Without Pivot TablesThe most basic way to calculate summary information is to use the SUMIF(), COUNTIF(), and AVERAGEIF() functions described in Chapter 13. To find the average annual purchases for an individual in New York using the worksheet shown in Figure 211, use a formula like this: =AVERAGEIF(C2:C11, "New York", E2:E11) This formula scans the City column (C2 to C11) looking for the text. Every time it finds a match, it adds the corresponding purchase amount from the Annual Purchases column (E2 to E11). The final result is the average of all these amounts. Next, you can make this formula more generic so that you don't need to create a new version for each city. Instead, change the formula so that it retrieves the text it should match (the city's name) from a cell just to the left of where you're going to place the formula. For example, this formula gets the city name from cell A15: =AVERAGEIF($C:$C, A15, $E:$E) Note that in this formula, all the search ranges are fixed as absolute references using the dollar sign ($). The search text isn't fixedthat way, when you copy the formula to a new row, the formula uses the search text on that row. Figure 212 shows the result of these "city" formulas, which reside in cells B15, B16, and B17. It also includes some formulas that total up the numbers using different criteria (like the values in the Education and Gender columns ).
In this example, building each table isn't terribly difficult, but the situation clearly becomes more tedious the more ways you want to compare the same data. It's not difficult to imagine a more realistic scenario where you may want to look at customer purchases based on age bracket , income level, and the answers to different customer survey questions. To get the full picture with this information, you need to build each table from scratch. In fact, in some of these more complex scenarios, you may need to group and then subgroup your information. Figure 213 shows a more advanced example of a table that calculates the variance in average annual purchases by city, and then shows the subdivided totals in each city by gender.
The summary in Figure 213 performs a twodimensional comparison. In other words, it compares two different groupingsone by city in different rows, and one by gender in different columns. This is a step up from the onedimensional summary tables you saw earlier, but it's also more difficult to correctly calculate. You could use the AVERAGEIFS() functions (Section 13.1.4), or create the table in two steps (first grouping the records by city, and then totaling them by gender). In either case, life gets much more complicated, and that's when pivot tables really shine . 21.1.2. Life with Pivot TablesWith a pivot table, you can create summary tables like the ones shown so far just by choosing the columns you want to compare. And once you've built your summary, you don't need to stick with itinstead, you can transform a purchasebyeducation table into a purchasebycity table just by dragging and dropping. You can even drill down into the details, apply filter criteria, and apply advanced subtotaling calculations. The following sections describe all of these techniques.
