Pivotal Pivot Tables

This article looks at how to turn data in Excel into information using PivotTables. By Liam Bastick, director with SumProduct Pty Ltd.

 

Query

I work with large tables of data which I need to interrogate on a regular basis.  A work colleague suggested I set up a PivotTable.  However, I’m an Excel novice and unsure how they work.  Could you give me some guidance please?

 

Advice

A PivotTable is a semi-dynamic, tabular summary of data.  It is one of Excel’s most flexible tools and can provide results that would take some time to reconstruct with sophisticated uses of functions such as SUMIF, SUMPRODUCT, etc.

Excel 2007 has increased PivotTable flexibility significantly from earlier incarnations.  However, as with many pre-Excel 2007 features, the location of various tools and options needs to be re-learned.  This article provides a basic overview for both Excel 2003 (and earlier) users as well as Excel 2007 users.

In order to get to grips with the basics of a PivotTable, I am going to use the attached Excel file example.

In this illustration, imagine we are a Head Office Analyst reviewing the electrical sales of four stores: imaginatively called North, South, East and West.

Creating a PivotTable on the same worksheet is fairly straightforward, albeit a little different between the Excel versions.  If the database is in one block (a ‘contiguous’ range), simply select any cell within the database and then:

 

Excel 2003 and earlier Excel 2007
  • Load up the Pivot Table Wizard, Data -> PivotTable and PivotChart Report… (ALT + D + P)
  • In Step 1 of 3 of the Wizard, choose ‘Microsoft Office Excel list or database’ as the data that you want to analyse and also select PivotTable as the report you want to create
  • In Step 2, confirm that the entire selection of data has been identified
  • In Step 3, put the report in the ‘Existing Worksheet’ and, say, choose cell L9
  • The layout can be detailed by selecting the ‘Layout’ button in the Wizard, but for this example we will click on ‘Finish’ instead
  • The Pivot Table Wizard does not appear to exist in Excel 2007, but if you select the keystrokes (ALT + D + P), the dialog box will indeed pop up albeit with restricted functionality
  • Consequently, it is probably easier to insert a Pivot Table from the Insert tab of the Ribbon, then click on the PivotTable icon, and then select PivotTable
  • The Create PivotTable dialog box appears.  Choose ‘Select a table or range’ and confirm the entire selection of data has been identified
  • For placement, select ‘Existing Worksheet ‘and choose, say, cell L9
  • Click ‘OK’ (layout cannot be constructed in a dialog box)

 

Notice that cell L9 is not the top left of the PivotTable, as you would expect.  In fact, L7 (same column, two rows higher) is the first cell for the Page Field insertion (see figure below).  When selecting where to place a PivotTable, always remember to select a cell two rows further down than you might otherwise think.

PivotTable Construct

The PivotTable has four areas where data fields may be placed (a data field is simply any one of the columns of the database, e.g. Date, Store, Item in this example):

PivotTable Construct


More than one field can be placed in any of these locations – the effect is a hierarchical grouping depending upon the order of placement.

In essence, a PivotTable is a three-dimensional summary of a database.  Consider it as a book: each page has a summary table of a selection of the data (for instance, in our example, each page could show the sales of each electrical item for each store on a particular date, so Page 1 is 1 April, Page 2 is 2 April, etc.).

To populate the layout, it is simply a case of dragging and dropping.  How this is done exactly depends on which version of Excel you have:

 

Excel 2003 and earlier Excel 2007
  • Once the PivotTable has been inserted, the PivotTable toolbar should appear (if not, from the dropdown menu, select View -> Toolbars -> PivotTable)
  • The PivotTable Field List dialog box should also appear (if not, right click on the layout and select ‘Show Field List’ from the shortcut menu
  • The fields can be dragged on to the layout using the mouse,  or simply select a field in the dialog box window and then make a choice from the drop down box and click ‘Add To’
  • In this example, Date is to be placed in the Page Area
  • Instead of a toolbar, two additional tabs are added to the end of the Ribbon – when the PivotTable is selected – Options and Design
  • The PivotTable Field List window pane should also appear (if not, click on the Field List icon in the Show / Hide section of the PivotTable Tools Options tab)
  • The fields can be dragged on to the layout using the mouse,  or simply select a field in the top dialog box window and drag it into one of the four windows below (‘Report Filter’ is the ‘Page Area’ equivalent)
  • In this example, Date is again to be placed in the ‘Page Area’

 

Using the Field List, drag the Date field into the Page Area, the Store field into the Row Area, the Item field into the Column Area and the Amount Invoiced field into the Data Area (Values in Excel 2007), viz.

Example PivotTable 1

The power of the PivotTable should already be apparent.  From the humble origins of a list of data, we can now see which store is leading in sales, enquire why there are no stereo sales in the South West and so on.  Using the drop down arrows in the table (you may need to make them visible in Excel 2007, PivotTable Tools -> Options -> Field Headers icon) or in the Field List pane in Excel 2007, we can filter for certain selections, e.g. North’s sales on 2 April:

Example PivotTable 2

But let’s not stop there.

Resetting the PivotTable, one key report would be to determine the amounts outstanding.  To do this, we need to construct a calculated field:

 

Excel 2003 and earlier Excel 2007
  • In the PivotTable toolbar, select PivotTable -> Formulas -> Calculated Field… (ALT + P + M + F)
  • In the Ribbon, select PivotTable Tools, Options tab, then click on the Formulas icon in the Tools section and click on Calculated Field

Insert Calculated Field Dialog Box

As a consequence of doing this, Excel may ask whether you want the destination cells to be replaced (the software thinks you want to replace or add to the Data Field).  Rather than worry about choosing ‘Yes’ or ‘No’ (obviously, choose one!), simply go to the Field List and de-select the Amount Invoiced field (or drag it off the layout from the top left hand corner) and choose the ‘Amount Outstanding’ calculated field instead:

Example PivotTable 3

One more thing we’ll do while we’re here: the business has a North West division and a South East division.  To see how these divisions have performed, we need to group the stores:

Example PivotTable 4

Example PivotTable 5

Example PivotTable 6

 

Just an Introduction…

This article was intended only as an introduction to PivotTables – there is plenty more you can do with them.  For example:

 

Handle With Care

 

If you have a query for this section, please feel free to drop Liam a line at liam.bastick@sumproduct.com or visit the website www.sumproduct.com