Monthly Archives: January 2012

Pivot Tables demystified

pivot tablesOnline businesses generate a lot of data. Sales data, marketing data, traffic data etc. Pivot tables can be a useful tool for analysing and extracting useful information from this sea of data. A lot of people seem to have heard of Pivot Tables without understanding what they are or how to use them. Despite the slightly cryptic name they are really just a way of summarizing tables of data. Nothing to be intimidated by. I’m going to try to demystify them here with a simple example.

Let’s imagine you have got an Excel spreadsheet with a month of (fictitious) sales transaction. It looks like this:

sales spreadsheet

You want to find out:

  1. The total value of sales of each product
  2. The number of sales of each product
  3. The total value of sales of each product by country
  4. The total value of sales of each product by day of the week

How would you do it? You can crunch the numbers using a calculator, but that is very tedious and error prone. If you are a programmer you can export the data to a .csv file and write a small program in your favourite language to read it in, crunch the data and write the results out. You probably think you can do it in 10 minutes, but I bet it will take you at least an hour to get it working and debugged. I did all the above in 1 minute and 20 seconds using Excel pivot tables.

Here is how you can do it (screenshots from Excel 2007). You can download the spreadsheet if you want to try it yourself.

Select all the data, including the header (A1 to D222).

Click on Insert in the Excel Ribbon bar.

Click on PivotTable.

pivot table 1

The Create Pivot Table window will appear. Click OK.

pivot table 2

The PivotTable Field List will appear. We want to find the number of sales for each product. Drag the product field to Column labels and the value field to Values. This gives us the total value of sales by product.

pivot table 3

To change this to the number of sales pull down the Sum of value drop-down list and select Value Field Settings….

pivot table 4

Change Summarize value field by from Sum to Count and click OK.

pivot table 5

The number of sales of each product are now shown.

pivot table 6

Now drag the country field to Row labels. Then click on Count of value, select Value Field Settings…, change it back to Sum and click OK. The total value of sales of each product by country is now displayed.

pivot table 7

We now need to add a day of the week column. Click on Sheet 1 and add a new column as shown.

pivot table 8

Now select all the data from A1 to E222 and insert a new pivot table, as before.

pivot table 9

Drag the fields as shown to get the total value of sales of each product by day of the week.

pivot table 10

(We’ll quietly ignore the fact that the number of days aren’t divisible by 7 in the data.)

We can even display by product, day of the week and country with one more drag.

pivot table 11

Excel also supports pivot charts if you prefer your results in graphical form.

pivot chart

Obviously this is a very simple example, but pivot tables can be used to quickly analyse much larger and more complex data sets. Next time you have got some data to analyse consider whether you would be better using pivot tables or pivot charts.