Excel: Calculations Outside of Pivot Tables

This page is an advertiser-supported excerpt of the book, Power Excel 2010-2013 from MrExcel - 567 Excel Mysteries Solved. If you like this topic, please consider buying the entire e-book.

Problem: I need to add a calculation in the grid outside of the pivot table that points to cells in the pivot table. Whenever I copy the formula, I get the exact same result!

Strategy: This started happening in Excel 2002. It is very annoying. I call it the GetPivotData bug.

Here is how it happens. In the figure below, you've already grouped daily dates to months and years. Normally, you could add a calculated item to calculate growth rate as (2015/2014)-1, but calculated items are not allowed in grouped pivot tables. So, you went to cell D5, typed an equals sign, clicked on C5, typed a slash, clicked on B5, and pressed enter. The 14.54% is the correct growth rate. So, you then copied the formula down. Somehow, the growth rate for every month is identical.

  1. Sales went down in March 2015 from March 2014, there is no way that 14.54% growth is correct.

    Select D5 and look in the formula bar. The formula there is =GETPIVOTDATA("œRevenue", $A$3,"Date",1, "Years", 2015) / GETPIVOTDATA( "œRevenue", $A$3,"Date",1, "Years",2014)-1. There is no way that you typed any of that. You simply used the mouse when building the formula.

    This also happens if you use the arrow keys. Equals Sign, Left, Slash, Left, Left, Minus, One, Enter will normally create a formula of =C5/B5-1, but in this case, you get the formula with two GETPIVOTDATA formulas.

    What is GETPIVOTDATA and how did it get in your worksheet? The Excel team is hoping that you would see GETPIVOTDATA, then go find out what it is and learn to love it and use it all the time. But that is never what happens. Instead, people are annoyed by it.

    As an aside, I spent eight years hating GETPIVOTDATA, but now I understand it and occasionally even use it. See "œCan I Save Formatting in a Template" for an example of when you would want to use it.

    The big question is how to enter a formula without getting the GETPIVOTDATA. One quick and easy way is to type the formula without using the mouse or the arrow keys. Just type =C5/B5-1. This creates a formula that will copy.

    The other method is to permanently turn off the feature to generate GETPIVOTDATA. To do this, chose File, Options, Formulas. There is a checkbox for Use GetPivotData Functions For PivotTable References. Turn this off.

    Additional Details: the other common problem with formulas outside of pivot tables is that they don't deal well with the changing size of pivot tables. In Q1, six reason codes are found, so the % of Total formula points to G$11.

  2. This works when there are six products.

    This doesn't work anymore in Q2, when only three reason codes are found.

  3. The Grand Total moves from row 11 to row 8. Your formula is still dividing by G11.

    The solution is to use an Excel trick to return the last value from column G. Also, use a custom number format where the third zone is blank in order to hide any 0 values that appear below the table.

  4. Two Excel tricks solve this problem.

For more resources for Microsoft Excel