Pop Group Pivot Tables Feb 05

download Pop Group Pivot Tables Feb 05

of 17

Transcript of Pop Group Pivot Tables Feb 05

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    1/17

    USING EXCEL PIVOT TABLES WITH

    POPGROUP

    February 2005Author: John AndelinPOPGROUPPivotTablesFeb05.doc,pdf

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    2/17

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    3/17

    Pivot Tables an introduction

    Excels pivot table feature is probably its most powerful tool. Creating a pivottable from a list enables you to summarise data in ways that would not

    otherwise be possible - and its amazingly fast. Procedures can also bewritten in VBA to generate and modify pivot tables. In versions of Excel from2000 onwards you can automatically generate PivotCharts at the click of abutton.

    POPGROUP provides a report generator but it is fixed to the specific types ofquery it was designed to address. Pivot tables allow the user to produce justabout 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 simpleexamples of their structure

    show what POPGROUP version 3 does to enable Excels pivot tablefunction to be used with population forecast output files

    illustrates the kind of tables that can be produced from POPGROUPflat files, which version 3 generates to provide the lists of data that pivottables require

    Pivot tables require a definition of the fields that are going to be presented inthe 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 thenumber of persons by age and sex in the population group that is

    3

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    4/17

    selected at the page level (Abba in the above illustration.) This level isoptional, 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; forexample, age groups. The age groups could be as produced in thePOPGROUP dump file, or as a new set of age groups that are derivedfrom the ages in the flat file. More than one row may be defined, inwhich case the rows of the subsidiary fields will be indented within thesuperior 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+ agegroups.

    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. Oncethe pivot table has been created, one may select any value within allthose available within the field.

    4. The data level: this is what is displayed within the body of the table: forexample, the sum of migrants at each age group, within the chosenpopulation group. This level is mandatory.

    One row level or one column level with the data level is the minimumrequirement.

    Design of the pivot table becomes a central issue when determining whichfields should be defined at the page level and which at the row and columnlevel. 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 oftable layout, produced from a sample flat file with just four fields populationgroup, age, sex and number of persons.

    4

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    5/17

    Simple table 1

    The page level is Population Group (called area in this example); Abba hasbeen 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

    5

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    6/17

    Simple table 2

    No page level defined

    Row fields are sex and age groupColumn field is population groupData field is sum of persons

    6

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    7/17

    Simple table 3

    Page level is Population Group (Abba selected from the drop down list)Row level is age groupColumn level is sex

    Data level is sum of persons

    7

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    8/17

    Simple table 4

    No page level definedRow level is age groupColumn levels are population group and sex

    Data level is sum of persons

    8

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    9/17

    Simple table 5

    This table shows that the data displayed can be one of a number of types, notjust sums or counts in this case as a percentage of another value.

    No page level definedRow level is age groupColumn levels are population group and sexData level is percentage of column total

    9

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    10/17

    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 flatfile of data. This procedure essentially takes the data contained in each of thepopulation group sheets and produces a list of all the groups data on a singlesheet the flat file. It provides column headings, which are the field namesthat Excels pivot table feature requires.

    The dump file produces a flat file with the following fields:

    The components file produces the following:

    10

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    11/17

    The flat file produced from a dump file is relatively straightforward, providing alimited 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 fieldsat page, row and column level to produce a pivot table for the requiredanalysis. The types of analysis that are possible depend on the type offorecast that has been run; for example, if no constraints have been specifiedthen clearly no pivot table that includes the constraint topic could beproduced. A review of the components file from which the flat file wasproduced will determine what pivot tables are possible and useful.

    11

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    12/17

    Examples from POPGROUP output files

    Example 1

    This example shows a report for male in-migration from the UK for a selectedpopulation group. The ages from the flat file have been grouped to producethe 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 Reportthen Microsoft Office Excel List or database andPivotTableClick NextThe Range contains the data highlighted on the data sheet.Click NextChoose New worksheetClick LayoutDrag 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 selectsummarize by sum (rather than the default count) and rename the source field if you wish}Click OKClick Finish

    A new sheet will now appear in the workbook with the resultant pivot table. You will see that the years are ratherunhelpfully presented as rows in the data column. To produce the more conventional cross tabulation of Age byYear, put the cursor on the grey Data cell and drag it to the cell containing the word Total. The crosstab will nowappear. Reformat the table with an appropriate number format and font. Use the Page level variables to select theRectype 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

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    13/17

    Example 2

    This example shows 3 page levels, with the table counting the number ofpersons 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 andPivotTableClick NextThe Range contains the data highlighted on the data sheet.Click NextChoose New worksheetClick LayoutDrag 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 selectsummarize by sum (rather than the default count) and rename the source field if you wish}Click OKClick Options and deselect Grand totals for columnsClick 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 layerde-select Constraint. In this example, the Start Popn next year was generated by using Excel to sum the positiveand negative flows.

    13

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    14/17

    Example 3

    This example shows 3 page levels, in which have been chosen specificvalues for this table, births. The table sums all births in each populationgroup 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 Toolbarthen select Pivot Table and PivotChart Reportthen Microsoft Office Excel List or database andPivotTableClick NextThe Range contains the data highlighted on the data sheet.Click NextChoose New worksheetClick LayoutDrag 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 selectsummarize by sum (rather than the default count) and rename the source field if you wish}Click OKClick Finish

    A new sheet appears with the resultant pivot table. Put the cursor on the grey Data cell and drag it to the cellcontaining 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 layerde-select County (the all groups sum produced by the POPGROUP forecast), so that the Grand Total is the sum ofjust the Countys Districts. Rename Grand Total to County (by overtyping).

    14

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    15/17

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    16/17

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

    800

    850

    900

    950

    1000

    1050

    1100

    1150

    1200

    1250

    1300

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

    scenario_00

    scenario_01

    scenario_02

    scenario_03

    scenario_04

    Topic Deaths stream All deaths group Blnkfrth

    Data

    scenario

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

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

    16

  • 8/14/2019 Pop Group Pivot Tables Feb 05

    17/17

    Useful sources of information on Pivot Tables

    For a Microsoft tutorial go to:

    http://office.microsoft.com/en-us/assistance/HA010346321033.aspx whichcontains 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