20.1. Summary Tables Revisited
When 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.
For example, consider the small table of information shown in Figure 201. 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 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.
The most basic way to calculate summary information is to use the SUMIF( ) and COUNTIF( ) functions described in Chapter 12. For example, to find the average annual purchases for an individual in New York, you first calculate the total purchases made by all New York customers. Here's the formula you need:
=SUMIF(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).
Once you have the total purchases, you need to divide this figure by the number of New York customers. To count the number of New York customers, you use the COUNTIF( ) function.
Here's the revised formula for finding the average annual purchase amount:
=SUMIF(C2:C11, "New York", E2:E11)/COUNTIF(C2:C11, "New York")
Finally, 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. (As shown in Figure 202, this group of "city" formulas resides in cells B15, B16, and B17.) Then, you can copy your formula into multiple rows. The formula won't change, but, in each row, the cell on the left will have a different value, instructing the formula to search for customers in a different city.

Here's the perfected formula:
=SUMIF($C:$C, A15, $E:$E)/COUNTIF($C:$C, A15)
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 202 shows several summary tables that use this technique for calculating averages.
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 might 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 would need to build each table from scratch.
In fact, in some of these more complex scenarios, you might need to group and then subgroup your information. Figure 203 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 203 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 far more difficult to correctly calculate. You could use the SUMPRODUCT( ) function (Section 12.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 .
With a pivot table, you can create summary tables like the ones shown in Figures Figure 202 and Figure 203 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.
Up To Speed How Pivot Tables Compare to Grouping and Data Lists 
Before going any further, why not get your head around how pivot tables fit in with other Excel features that you've already seen? In Chapter 14, you learned about two techniques for grouping and organizing data. These include:
Compared to either of these features, pivot tables are more flexible and more dynamic. A single pivot table can group and subtotal the same list in different waysall you need to do is drag and drop your columns. Thanks to this flexibility, pivot tables are a much more flexible tool for analyzing your information and discovering hidden relationships. 