cellmatrix.net

Pivot Table Difference Between Columns

When I most need it, I always seem to forget how to compute the difference between two pivot table columns. So, it's about time to put it in writing. Assume the following data:

image

Create a simple pivot table with the years as columns and the areas as rows.

image

Next, eliminate the row totals. To do so, right-click any cell within the pivot table and go to Table Options. Deselect "Grand total for rows" from the format options area of the Table Options dialog box.

At this point it's time to create a calculated item that subtracts the 2008 data from the 2007 data. Right-click on the year (cell B2) and select Show Pivot Table Toolbar. In the Pivot Table toolbar, choose Formulas -> Calculated Item. The following dialog box will appear:

image

Add the formula for the calculated item as shown below:

image

To make all of the accountants happy, we need to make the most recent year appear as the first column of the table. To do so, right-click within the column titles (2008, 2007, or Difference) -> Order. You can then move the any of the columns to the right or left to achieve the desired look.

The end-result looks like this:

image

Pivot Table Fill

By their nature pivot tables do not show rows that repeat. The pivot table shows the first unique row descriptor and then repeats blank cells until the next unique descriptor is shown. You might need to show all descriptor values - for example if you want to load the results of a pivot table into an ACCESS database.

If you first copy the pivot table as values, you can then apply the macro below to the descriptor range. The macro loops through the descriptor range and fills the empty cells with the descriptor values.

Sub PivotTableFill()
    Dim Rng As Range
    For Each Rng In Range("A1", "C100")
        If IsEmpty(Rng) = True Then
            Rng.Value = Rng.Offset(-1, 0).Value
        End If
    Next Rng
End Sub