Docsity

Advanced Excel, Lecture notes of Statistics

Partial preview of the text

Download Advanced Excel and more Lecture notes Statistics in PDF only on Docsity!

Excel 2007

PivotTables

Contents

  • PivotTables.........................................................................................................................
    • PivotTable datasets
    • Creating a PivotTable
    • Arranging your data
    • Changing the way values are displayed
  • Calculated Fields
  • Calculated Items
    • Formatting values
    • Grouping data
    • Sorting and Filtering Data
    • Refreshing a PivotTable
    • Extending the dataset
  • Dynamic Range Names
    • Applying the Named Range to a new PivotTable
    • Applying the Named Range to an existing PivotTable
    • Formatting PivotTables
    • GetPivotData Function
  • PivotCharts
    • Creating a PivotChart with a PivotTable

the PivotTable. Where a particular value in a row and a particular value in a column intersect, the data in the Amount field is summarised in the centre. By default the calculation used is Sum. So, for example, where Geography and Paper intersect the total amount of Paper ordered by Geography will be displayed i.e. 26.

Creating a PivotTable

  1. Click anywhere within the range of data you wish to use to create your PivotTable.
  2. From the Insert tab select PivotTable. Excel will display the Create PivotTable dialog box, automatically select the entire range and add the reference for that range to the Table/Range box.
  3. Select New Worksheet or Existing Worksheet depending on where you want your PivotTable to appear.
  4. If you choose to put the PivotTable into the existing worksheet, you need to make sure you tell the wizard where to place it. The easiest way to do this is to click into an area in the existing spreadsheet. The cell reference will appear in the Location box.
  5. Click on the OK button. A blank PivotTable and PivotTable Field List will be displayed. Two new PivotTable Tools tabs become available on the Ribbon: Options and Design. Any column headings become fields in the Field List.

Note that the Field List and additional Tabs on the Ribbon only appear when you click on the PivotTable.

Arranging your data

  1. From the Field List , drag the fields with the data you want to display in rows to the area on the PivotTable diagram labeled Drop Row Fields Here or into the Row Labels box.
  2. Drag the fields with the data you want to display in columns to the area labeled Drop Column Fields Here or into the Column Labels box.
  3. Drag the fields that contain the data you want to summarize to the area labeled Drop Value Fields Here or into the Values box. Excel assumes Sum as the calculation method for numeric fields and Count for non-numeric fields.
  4. If you drag more than one data field into rows or into columns, you can re-order them by clicking and dragging the columns on the PivotTable itself or in the boxes.
  5. To rearrange the fields at any time, simply drag them from one area to another.
  6. To remove a field, drag it out of the PivotTable report or untick it in the Field List. Fields that you remove remain available in the field list.

Example

This example shows Average A-Level Points by College. To change the number format: Right-click in the PivotTable, and choose Number Format

Adding additional calculations

To display more than one calculation in the Values area, add the same Field twice. In the example shown below, the Sum and Count are being shown for the Fees Paid to each College. Count of Fees Paid is the number of fees paid to each College.

Field List and Areas Section

Calculated Fields

You can have additional calculations, which are not part of the source data, in your PivotTable. You will use the fields containing numeric data to create new fields. They will become part of the PivotTable and can be used in further calculations.

The following example shows a new field called Increase created by using the field Fees Paid and multiplying by 10%. The new field ( Increase ) can then used in another calculation.

Click anywhere in PivotTable a. On the Options tab, Tools group click on the Formulas button,

then Calculated Field b. Type in name you want to give your new field eg: Increase c. Then in Formula field the calculation required eg =’Fees Paid’*10%

NB: You can type in the field names you want use in the calculation, or select them from the list and use the Insert Field button

Formulae can be modified =’Fees paid’*7% and calculations will be updated immediately.

You can use the new field to create another calculated field: Name: NewFee Formula= Fees Paid+Increase

Calculated Items

This is a feature which allows you to create calculations within the PivotTable using the summary figures there. For example, you may want add two fields together to form another heading.

The example below shows new calculated items (field heading NorthEast and SouthWest) which add together North and East sales figures and South and West figures respectively.

  1. Start by clicking in the column or row heading which you want to include in the calculation
  2. In Fields : click on the field name which contains the items you want to use in you formula
  3. Select the item you want from the Items : list and click on the Insert Item button
  4. Build up your formula using the fields and items as required

Delete or modify calculated items by clicking on the drop-down at the side of the Name: field

Formatting values

  1. Display the Field Settings dialog box as shown above.
  2. Click on the Number Format button.
  3. Select the Category you want and set any options. For example, select Number and enter the number of decimal places to display the data to. 4. Click OK and OK again and your cells will be reformatted.

Displaying values as a

percentages:

  1. Display the Field Settings dialog box as shown above.
  2. Click on the Show Values As tab.
  3. Select Percentage of Row Total or Percentage of Column Total

Example

In the example below, products ordered (paper and toner) are shown for each department as a percentage of the total for all departments. This is done by displaying values as a percentage of the column total.

Helpful hint : The Field Settings dialog box can be used to change the name of any Field in the PivotTable. For example, this can be used to change the name of Dept to Department.

Grouping numeric items into ranges

  1. Select a single field item in the PivotTable.
  2. Click on the Group Field button on the PivotTable Tools Options tab.
  3. Excel displays a dialog box in which it automatically enters a start and end number based on the highest and lowest values in your range. It also lists a number for the intervals to group by.
  4. Select an appropriate interval and click OK.

Example

In the example below, marks are grouped in intervals of 10 so, for example, you can see that 1 candidate got between 40 and 49 marks in COMPB401 and 4 got between 50 and 59 marks.

Grouping date or time data

  1. Select a single field item in the PivotTable.
  2. Click on the Group Field button on the PivotTable Tools Options tab.
  3. Excel displays a dialog box in which it automatically enters a start and end date. It also lists a choice of intervals to group by.
  4. Select an appropriate type of interval (e.g. Months) and click OK. If you select Days you can choose the number of Days. You can select more than one. For example if you select Months and Years, the data will be grouped by year and then displayed for each month as shown.

Ungrouping

Click on the field you want to ungroup and click on the Ungroup button on the PivotTable Tools Options tab to ungroup specific custom groups, click on the name of the group and then the Ungroup button.

Default grouping for multiple values

Note that grouping automatically occurs where you have more than one Field in the same area (Row or Column). In the example below, the Department and Term fields are both added to the PivotTable as Row Labels. By putting the fields in the order Department then Term, data is grouped by Department. Subtotals are automatically displayed for each grouping i.e. by Department.

Note that you can remove Subtotals in the Field Settings dialog box.

Sorting row or column labels:

  1. Click on the drop down arrow next to the Field name.
  2. Click on Sort A to Z or Sort Z to A for text, Sort Smallest to Largest or Largest to Smallest for numeric data or Sort Oldest to Newest or Newest to Oldest for dates.

Refreshing a PivotTable

When data is changed in the PivotTable source list, the PivotTable does not automatically recalculate. To refresh the table:

Select any part of the PivotTable.

  1. On the PivotTable Tools Options tab, click on the Refresh button.

OR

Right-click in the PivotTable, and choose Refresh

You can also have your PivotTables refreshing every time you open the workbook. Click on Options button on the Options tab and tick Refresh data when opening the file on the Data tab:

Extending the dataset

If you add additional columns or rows to you will need to extend the data source of the PivotTable to include them.

  1. Click on the Data Source button on the PivotTable Tools Options tab.
  2. Edit the range in the Table/Range box to include your entire dataset and click OK.

Applying the Named Range to a new PivotTable

When you create a new PivotTable, you define the name as the source. Type the range name in he Create PivotTable dialog box:

Applying the Named Range to an existing PivotTable

To use the new name in your PivotTable, you need to change the data source:

  1. Select any cell in the PivotTable
  2. On the Options tab, click the Change Data Source button:
  3. Type in the dynamic range name. Or press F3 for a list of names

Formatting PivotTables

Various options can be used to change the look of PivotTables. These can be found on the PivotTable Tools Design tab. You can apply a PivotTable Style and choose whether or not to have banded columns or rows (i.e. where rows or columns are coloured in alternate shades.

Note that buttons to add or remove Subtotals and Grand Totals are also available on the Design tab.

GetPivotData Function

The =GetPivotTable function will allow you to get information from the PivotTable by referencing field names instead of cell references:

The syntax is: GETPIVOTDATA ( data_field , pivot_table ,field1,item1,field2,item2,...)

=GETPIVOTDATA("total sales",$A$3) Will return the Grand Total 1738900

=GETPIVOTDATA("total sales",$A$3,"area","south") Will return Total sales for the Area South - 327600

=GETPIVOTDATA("total sales",$A$3,"area","south","salesperson","brown") Will return Salesperson Brown’s Total Sales in the South Area - 123200

=GETPIVOTDATA("total sales",$A$3,"salesperson”,”smith) Will return Salesperson Smith’s Total Sales - 398500