Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

USING EXCEL PIVOT TABLES WITH POPGROUP

February 2005 Author: John Andelin


POPGROUPPivotTablesFeb05.doc,pdf

POPGROUP output includes flat files, the results from one or more forecasts on a single excel sheet. These population forecasts and components of population change can be analysed with statistical packages or with Excel Pivot Tables. This document describes Pivot Tables and gives examples of their use with POPGROUP output files.

Contents
Pivot Tables an introduction..........................................................................3 Simple table 1...............................................................................................5 Simple table 2...............................................................................................6 Simple table 3...............................................................................................7 Simple table 4...............................................................................................8 Simple table 5...............................................................................................9 POPGROUP v3 and pivot tables ...................................................................10 Examples from POPGROUP output files .......................................................12 Example 1 ..................................................................................................12 Example 2 ..................................................................................................13 Example 3 ..................................................................................................14 Example 4 ..................................................................................................15 Useful sources of information on Pivot Tables...............................................17

Pivot Tables an introduction


Excels pivot table feature is probably its most powerful tool. Creating a pivot table from a list enables you to summarise data in ways that would not otherwise be possible - and its amazingly fast. Procedures can also be written in VBA to generate and modify pivot tables. In versions of Excel from 2000 onwards you can automatically generate PivotCharts at the click of a button. POPGROUP provides a report generator but it is fixed to the specific types of query it was designed to address. Pivot tables allow the user to produce just about any report that relates one set of data items to any other. This paper sets out to: describe briefly what Excel pivot tables are, giving a few simple examples of their structure show what POPGROUP version 3 does to enable Excels pivot table function to be used with population forecast output files illustrates the kind of tables that can be produced from POPGROUP flat files, which version 3 generates to provide the lists of data that pivot tables require

Pivot tables require a definition of the fields that are going to be presented in the table. Up to four levels may be defined for the makeup of the table:

1. The page level: field(s) that the table will report on, appearing at the top of the pivot table page. For example, the table could report on the number of persons by age and sex in the population group that is

selected at the page level (Abba in the above illustration.) This level is optional, as will be seen in some of the examples that follow. 2. The row level: the field(s) that will appear as the rows of the table; for example, age groups. The age groups could be as produced in the POPGROUP dump file, or as a new set of age groups that are derived from the ages in the flat file. More than one row may be defined, in which case the rows of the subsidiary fields will be indented within the superior fields. Once the pivot table has been set up, and displayed, individual values of the row fields may easily be selected: for example, within age group one may wish to display only the 0 to 4 and 75+ age groups. 3. The column level: the field(s) that will appear as columns in the table: for example, sex. Again, more than one field may be chosen. Once the pivot table has been created, one may select any value within all those available within the field. 4. The data level: this is what is displayed within the body of the table: for example, the sum of migrants at each age group, within the chosen population group. This level is mandatory. One row level or one column level with the data level is the minimum requirement. Design of the pivot table becomes a central issue when determining which fields should be defined at the page level and which at the row and column level. If a number of row fields and column fields are defined the resulting table may be very unwieldy and difficult to interpret. There follows a set of simple tables that demonstrate the different types of table layout, produced from a sample flat file with just four fields population group, age, sex and number of persons.

Simple table 1
The page level is Population Group (called area in this example); Abba has been selected as the subject area of the report. Two row fields are defined as Sex and Age No column field is defined. The data field is of number of persons

Simple table 2
No page level defined Row fields are sex and age group Column field is population group Data field is sum of persons

Simple table 3
Page level is Population Group (Abba selected from the drop down list) Row level is age group Column level is sex Data level is sum of persons

Simple table 4
No page level defined Row level is age group Column levels are population group and sex Data level is sum of persons

Simple table 5
This table shows that the data displayed can be one of a number of types, not just sums or counts in this case as a percentage of another value. No page level defined Row level is age group Column levels are population group and sex Data level is percentage of column total

POPGROUP v3 and pivot tables


In version 3 of POPGROUP the components file and the (optional) dump file, generated when a scenario is run, each provide a procedure to create a flat file of data. This procedure essentially takes the data contained in each of the population group sheets and produces a list of all the groups data on a single sheet the flat file. It provides column headings, which are the field names that Excels pivot table feature requires.
The dump file produces a flat file with the following fields:

The components file produces the following:

10

The flat file produced from a dump file is relatively straightforward, providing a limited number of values for each field. The components flat file contains a large number of possible stream values, and use of this file needs some careful thought about the combination of fields at page, row and column level to produce a pivot table for the required analysis. The types of analysis that are possible depend on the type of forecast that has been run; for example, if no constraints have been specified then clearly no pivot table that includes the constraint topic could be produced. A review of the components file from which the flat file was produced will determine what pivot tables are possible and useful.

11

Examples from POPGROUP output files


Example 1
This example shows a report for male in-migration from the UK for a selected population group. The ages from the flat file have been grouped to produce the new field of Broad Age Group

How it was done:


Take a single year of age flat file from a POPGROUP dump file. Highlight the entire sheet in the flat file. Click on Data in the Excel Standard Toolbar then select Pivot Table and PivotChart Report then Microsoft Office Excel List or database and PivotTable Click Next The Range contains the data highlighted on the data sheet. Click Next Choose New worksheet Click Layout Drag Rectype, Sex, Group and Topic to the Page layer. Drag Age to the Row layer. Drag the years to be reported on to the data area. {Double click on the variable name and select summarize by sum (rather than the default count) and rename the source field if you wish} Click OK Click Finish A new sheet will now appear in the workbook with the resultant pivot table. You will see that the years are rather unhelpfully presented as rows in the data column. To produce the more conventional cross tabulation of Age by Year, put the cursor on the grey Data cell and drag it to the cell containing the word Total. The crosstab will now appear. Reformat the table with an appropriate number format and font. Use the Page level variables to select the Rectype of Flow, Topic of Mig_InUK, Sex of M and a population group. At this stage, the ages are still single year. To produce groupings of your choice: Highlight the ages you want to group Right click the mouse: select Group and show detail and Group Double click on the group name allocated, to remove the single year age detail Edit the group name with something more appropriate Repeat these first four steps for each new age group to be created Right click on Age and then Hide Double click on Age2 and change its name.

12

Example 2
This example shows 3 page levels, with the table counting the number of persons for each measure (births, deaths etc) in each year, 1991 to 2002. The table is a summary of these measures for the County.

How it was done:


Take a single year of age flat file from a POPGROUP dump file. Highlight the entire sheet in the flat file. Click on Data in the Excel Standard Toolbar then select Pivot Table and PivotChart Report then Microsoft Office Excel List or database and PivotTable Click Next The Range contains the data highlighted on the data sheet. Click Next Choose New worksheet Click Layout Drag Sex, Age and Group to the Page layer. Drag Topic to the Row layer. Drag the years to be reported on to the data area. {Double click on the variable name and select summarize by sum (rather than the default count) and rename the source field if you wish} Click OK Click Options and deselect Grand totals for columns Click Finish

A new sheet appears with the resultant pivot table. Put the cursor on the grey Data cell and drag it to the cell containing the word Total for a proper crosstab. Reformat the table with an appropriate number format and font. Use the Page level variables to select All in Sex and All ages; select a population group. In the Topic row layer de-select Constraint. In this example, the Start Popn next year was generated by using Excel to sum the positive and negative flows.

13

Example 3
This example shows 3 page levels, in which have been chosen specific values for this table, births. The table sums all births in each population group for each chosen year.

How it was done:


Take a single year of age flat file from a POPGROUP dump file. Highlight the entire sheet in the flat file. Click on Data in the Excel Standard Toolbar then select Pivot Table and PivotChart Report then Microsoft Office Excel List or database and PivotTable Click Next The Range contains the data highlighted on the data sheet. Click Next Choose New worksheet Click Layout Drag Rec_type, Sex, and Topic to the Page layer. Drag Group to the Row layer. Drag the years to be reported on to the data area. {Double click on the variable name and select summarize by sum (rather than the default count) and rename the source field if you wish} Click OK Click Finish

A new sheet appears with the resultant pivot table. Put the cursor on the grey Data cell and drag it to the cell containing the word Total for a proper crosstab. Reformat the table with an appropriate number format and font. Use the Page level variables to select All in Sex, Flow in Rec_type and Births in Topic. In the Group row layer de-select County (the all groups sum produced by the POPGROUP forecast), so that the Grand Total is the sum of just the Countys Districts. Rename Grand Total to County (by overtyping).

14

Example 4
Example of a pivot table from a flat file produced by appending a series of components files generated from alternative scenarios

How it was done:


Take the flat file produced by appending the flat file outputs from a number of POPGROUP components files (i.e. the components files output from alternative scenarios). Highlight the entire sheet in the flat file. Click on Data in the Excel Standard Toolbar then select Pivot Table and PivotChart Report then Microsoft Office Excel List or database and PivotTable Click Next The Range contains the data highlighted on the data sheet. Click Next Choose New worksheet Click Layout Drag Topic, Stream and Group to the Page layer. Drag Scenario to the Column layer. Drag the years to be reported on to the data area. {Double click on the variable name and select summarize by sum (rather than the default count) and rename the source field if you wish} Click OK Click Options and deselect grand total for rows and columns Click Finish

A new sheet appears with the resultant pivot table. Reformat the table with an appropriate number format and font. Use the Page level variables to select Deaths in Topic, All Deaths in Stream and a population group in Group.

15

By highlighting the pivot table, right clicking the mouse and selecting PivotChart, the following chart is automatically produced.

Topic Deaths stream All deaths group Blnkfrth 1300

1250

1200

1150

1100

scenario scenario_00 scenario_01 scenario_02 scenario_03 scenario_04

1050

1000

950

900

850

800 Sum of 1991 Sum of 1996 Sum of 2001 Data Sum of 2006 Sum of 2011 Sum of 2016

Once the chart has been produced, the standard Excel charting facilities may be used to change the formats, add titles, select minimum/maximum values to be displayed, etc.

NOTE: the V3 workbook Summ Comparison uses the Summ workbooks to produce a series of pivot tables and charts covering the components and population summaries of all, or a selected number of, the scenario results in POPGROUPs Output directory. See the user manual for further details of the Summ Comparison workbook.

16

Useful sources of information on Pivot Tables


For a Microsoft tutorial go to: http://office.microsoft.com/en-us/assistance/HA010346321033.aspx which contains links to other material

Further tips are available from:


www.exceltip.com/exceltips.php?view=category&ID=32

And Excels Help facility is very useful at answering specific queries.

17

You might also like