Analyze Sales With a Pivot Table

This week, John Walkenbach, aka Mr. Spreadsheet, used a pivot table report to analyze his website’s Amazon sales for 2009. Here’s a screenshot of the results, showing the top sellers, and number of units sold.

JWalkAmazon

John knows a thing or two about Excel, having written over 40 Excel books, so take a look at the full list, and see if there’s something there that will help you.

Excel 2007 Power Programming with VBA

I bought a copy of John’s Excel 2007 Power Programming with VBA a couple of years ago, and highly recommend it. The book is a great reference when you’re learning VBA, or upgrading from an earlier version of Excel.

In its 1104 pages, the book covers pretty much everything you need to know about Excel VBA, and comes with a CD that contains:

  • Sample files for the book’s VBA tutorials
  • A searchable PDF version of the book

And best of all, there’s a chapter on Pivot Table Programming, that will help you get started with the new pivot table features in Excel 2007. In that chapter, you’ll discover what’s new in Excel 2007 pivot tables, and learn how to:

  • create pivot tables with VBA
  • create a complex pivot table
  • create multiple pivot tables
  • use VBA to change a summary table to a worksheet table

_____________

Pivot Table Tricks

Chandoo, at the Pointy Haired Dilbert blog, has posted 5 Excel Pivot Table tricks today. His blog posts are always informative and entertaining, so go and take a look.

The 5 Pivot Table tricks are:

  1. Drill Down Pivot Tables
  2. Change Summary from Total
  3. Slice and Dice Pivots
  4. Difference from Last Month
  5. Calculated Fields in Pivots

Did you know all those pivot table tricks? Learn anything new?

______________

For more information on Pivot Tables, please see the Pivot Table Tutorials on the Contextures Website.

______________

Excelerators Quiz for Excel Power Users

NOTE: This contest ended in 2010, and link is no longer owned by the PowerPivot team.

The team at PowerPivot for Microsoft Excel 2010 created the Excelerators Quiz, where you can test your Excel skills. To make the challenge more exciting, they’re sponsoring a giveaway on the Contextures blog (for USA residents only).

The blog giveaway prize has a total value of over $250, and will include a Dell ST2310 23 inch flat panel monitor, keyboard, and mouse.

How to Enter

To enter the giveaway, after you take the Excelerators Quiz, go to the Contextures blog, read the rules, and add a comment. In your comment:

  • Create your own unique question for the Excelerators Quiz.
  • Make your question multiple choice, with the correct answer as one of the four options.

The Alpha Geek Challenge

The PowerPivot team has also launched an Alpha Geek Challenge for more advanced excel geeks. Donald Farmer will host a PowerPivot competition in which the Grand Prize winner will receive an all-expenses paid trip to the 2010 Microsoft BI Conference in New Orleans, LA in June.

After you finish the Excelerators Quiz, and enter the Contextures blog giveaway contest, see how you do in the Alpha Geek Challenge!

_____________

Remove Calculated Field From Excel Pivot Table

After you create a calculated field in an Excel pivot table, you might want to remove it from the pivot table layout. You can temporarily remove a calculated field, or you can permanently remove it.

In this example, the pivot table has a calculated field named Bonus. It appears in the Values area as Sum of Bonus. You could hide the Bonus calculated field, or delete it from the pivot table.

PivotCalcField01

Temporarily Remove a Calculated Field

To temporarily remove a calculated field from a pivot table, follow these steps:

  1. In the pivot table, right-click a cell in the calculated field. In this example, we’ll right-click the Bonus field.
  2. In the popup menu, click the Remove command that shows the name of the calculated field.

PivotCalcField02

The calculated field is removed from the pivot table layout, but remains in the PivotTable Field List.

Later, you can add a check mark to the calculated field in the PivotTable Field List, to return it to the pivot table layout.

Permanently Remove a Calculated Field

To permanently remove a calculated field, follow these steps:

  1. Select any cell in the pivot table.
  2. On the Ribbon, under the PivotTable Tools tab,  click the Options tab.
  3. In the Tools group, click Formulas, and then click Calculated Field.
  4. From the Name drop down list, select the name of the calculated field you want to delete.
    • PivotCalcField03
  5. Click Delete, and then click OK to close the dialog box.

______________

For more information on Pivot Tables, please see the Pivot Table Tutorials on the Contextures Website.

______________

Filter a Pivot Table for Nonconsecutive Dates

In an Excel 2007 pivot table, you can filter a date field by using the Date Filters option in the Row Labels drop down. For example, you can select all the dates between two specific dates, or filter for a dynamic range, such as Last Week.

DateFilter01 

However, when you use the row label date filters, you can only select a consecutive date range, or one specific date. You can’t select two or more nonconsecutive dates.

For example, in the screen shot above, the Work Date field is in the Row Labels area, and Labor Hours (Sum of LbrHrs) is in the Values area. In the Work Date field, you can’t use the Date Filters option to select to select January 13th, 17th and 21st.

Manually Select the Dates

Instead of using the date filter options, you can manually select items in the Row Labels drop down list. To manually filter dates in the Row Labels filter list, follow these steps:

  1. In the pivot table, click the arrow on the Row Labels heading.
  2. In the list of dates, remove the check mark from Select All, to remove all the check marks from the list.
  3. Add check marks to the dates you want to see, and then click OK.

The pivot table now shows results for work done on the selected dates, and you can focus on that data.

______________

For more information on Pivot Tables, please see the Pivot Table Tutorials on the Contextures Website.

______________

Change All Pivot Table Value Fields to SUM

Sometimes when you add fields to the Values area of a pivot table, they appear as Count of Field instead of Sum of Field. In the screen shot below, the Quantity field shows the COUNT, and the TotalPrice field shows the SUM.

pivot table Summary Macro_01

COUNT Summary Function

The COUNT summary function is the default if a field in the pivot table’s source data contains blank cells, or cells with text. For example, in a column of invoice dates, someone might mistype a month name, so it isn’t recognized as a valid date. Or, in a column of sales quantities, you might have typed “N/A”, instead of a number, or maybe you left a blank cell to fill in later.

In these cases, where the source column contains blank cells or text, the summary function defaults to Count; otherwise, it defaults to Sum.

Change the Summary Function

You can manually change the summary function from Count to Sum, after the Values fields have been added. Or, to make things easier, you can run a macro to change the summary function.

This sample macro changes all the Values fields in the first pivot table on the active sheet to use the Sum function (xlSum). The code refers to the pivot table by index number (1), instead of using a specific name (“PivotTable1”), and that makes the macro more flexible.

You can copy this code to a regular code module in your workbook, and run it when you want to change the summary functions for all the Value fields.

Sub SumAllValueFields()
  Dim pt As PivotTable
  Dim pf As PivotField
  Dim ws As Worksheet

  Set ws = ActiveSheet
  Set pt = ws.PivotTables(1)
  Application.ScreenUpdating = False

    pt.ManualUpdate = True
    For Each pf In pt.DataFields
      pf.Function = xlSum
    Next pf
    pt.ManualUpdate = False

  Application.ScreenUpdating = True
  Set pf = Nothing
  Set pt = Nothing
  Set ws = Nothing
End Sub

Download the Sample File

You can download the sample file with the Change Summary Function to Sum sample code, from my Contextures website.

The zipped file is in xlsm format, and contains macros. You can run the macro in the sample file, or copy the Excel VBA code to a regular code module in another workbook, and run it there.

Pivot Power Add-in

If you’ve bought a copy of my Pivot Power Premium add-in, this feature is included. Just click the commands in the Data Fields group, and you can quickly change all fields to SUM, or any other summary function. Or, select specific value fields, and just change those to a different summary function.

sumselectedvalues

______________

Remove a Pivot Table Style in Excel 2007

When you create a pivot table in Excel 2007, a default PivotTable style is automatically applied to a pivot table. For example, in the screen shot below, the pivot table uses the Pivot Style Light 16.

Pivot Style Light 16

Remove the Pivot Table Style

In some workbooks, you might prefer to have a pivot table with no fill color or header formatting.  In the PivotTable Styles gallery, you can apply a special style to remove the existing style.

Follow these steps to clear the PivotTable style:

  1. Select a cell in the pivot table.
  2. On the Ribbon, click the Design tab.
  3. In the PivotTable Styles gallery, click the first style, None, at the top left of the Light styles.

Pivot Style None

Pivot Table Style Removed

After you click the None option, the existing style is removed, and a thin border remains around the pivot table sections. The worksheet gridlines, if displayed, are not visible within the pivot table.

Also, when no PivotTable style is applied, the preview function does not work if you point to a different style in the PivotTable Styles gallery.

Clear the Pivot Table Style

Another way to remove the PivotTable style is to click Clear, at the bottom left of the PivotTable Styles gallery.

Pivot Style Clear

______________

For more information on Pivot Tables, please see the Pivot Table Tutorials on the Contextures Website.

______________

Keep Formatting in Excel 2007 Pivot Table

Even though a pivot table is automatically formatted when you create it, you can add your own formatting later. For example, in the pivot table shown below, I’ve added colour to the subtotal rows, and made column B narrow.

PivotFormat01

However, some of that pivot table formatting might be lost if you refresh the pivot table or change its layout. Even if you select a different item in the report filter, the formatting could be lost.

Here’s what the same pivot table looks like, after I select an order date from the report filter.

PivotFormat02

Preserve the Formatting

Most pivot table formatting can be preserved if you change the Format options in the PivotTable Options dialog box.

  1. Right-click a cell in the pivot table, and click PivotTable Options.
  2. On the Layout & Format tab, in the Format options, remove the check mark from Autofit Column Widths On Update. This will prevent column widths from changing, if you have manually adjusted them.
  3. Add a check mark to Preserve Cell Formatting on Update
  4. Click OK.

PivotFormat03

Apply Formatting

After changing these Pivot Table options, the formatting should stick. When you apply formatting to the Pivot Table, do the following:

  1. Ensure that Enable Selection is turned on.
  2. Unless you want to format a single cell, use the pivot table selection technique to select the elements you want to format (point to the top or left edge of the element, and then click when the black arrow appears).

______________

P.S. For more information on Pivot Tables, please see the Pivot Table Tutorials on the Contextures Website.

_________________

Allow Drag-and-Drop in Excel 2007 Pivot Table

In Excel 2003, you could drag fields from the PivotTable Field List onto the pivot table layout on the worksheet.

In Excel 2007, you can only move the fields to the areas in the PivotTable Field List. In the screen shot below, if you try to drag the Promo field onto the pivot table, the cursor shows an X. The drag-and-drop feature doesn’t work.

PivotDrag01

Change the Pivot Table Settings

If you’d like to drag the pivot fields onto the worksheet layout, you can change a setting in the pivot table options.

  1. Right-click a cell in the pivot table, and click PivotTable Options.
  2. On the Display tab, add a check mark to Classic PivotTable Layout.PivotDrag02
  3. Click OK, to close the PivotTable Options dialog box.

Drag the Pivot Table Fields

After you change the setting, the pivot table on the worksheet shows a blue border around each region.

PivotDrag03

You can now drag the pivot fields from the PivotTable Field List onto the worksheet, or drag the fields to a different part of the pivot table.

  1. Point to a field label in the pivot table layout
  2. When the pointer changes to a four-headed arrow, drag the field label to a different area

PivotDrag04

You can use the same technique to drag fields into the pivot table layout from the PivotTable Field List, or drag field labels out of the pivot table layout.

Pivot Table in Tablular Form

When you change the setting to Classic PivotTable layout, the pivot table’s report layout automatically changes to Tabular form.

You can use Tabular form, or Outline form, with the Classic PivotTable layout. If you change to Compact form, the blue borders are still visible when the pivot table is active. However, you won’t be able to drag-and-drop the fields.

Video: Classic Layout

In this video, you’ll see the manual steps required to format a pivot table in Classic Style, so you can drag and drop the fields, right on the worksheet. There are several steps in the process:

  • change subtotal setting
  • change report layout of the pivot table
  • change pivot table style
  • change the pivot table display options
  • change setting to clear old items in Pivot Table
  • format each value field as number format
  • sort each row field alphabetically.

Save Time with a Macro: Near the end of the video, you’ll see how much quicker it is to run the recorded macro, to format the pivot able in seconds, instead of minutes. To get that macro, go to the Classic Layout Pivot Table Format Macro page, on my Contextures site.

___________________

Change Field Names in Pivot Table Source Data

Occasionally, you might need to change a column heading in the pivot table’s source data. For example, you could change a column heading from Qty to Quantity, to make it easier to understand.

Pivot Table Field Name 01

However, when you refresh the pivot table after making the changes, the renamed field will disappear from the pivot table layout. In our example, the Qty field is removed from the layout. It isn’t automatically replaced by the Quantity field, even though it’s in the same column heading cell in the source data.

Pivot Table Field Name 02

If you change the column headings, you’ll have to add the revised field to the pivot table layout again. If you had number formatting in the old pivot field, you’ll have to reapply the number formatting you had previously applied. 

Change Captions Instead

If possible, instead of changing the column headings in the source data, create custom names for the fields in the pivot table instead.

For example, to create a custom name for the Qty field:

  1. In the pivot table, click on the cell that contains the pivot field name, Qty.
  2. Type the custom name, Quantity.
  3. Press the Enter key, to complete the renaming.

Pivot Table Field Name 03

_____________________

For more information on Pivot Tables, please see the Pivot Table Tutorials on the Contextures Website.

_________________