Reputation: 6713
Here is my data:
I created a pivot table from the data and created a calculated field called "% Error" defined like this:
I set the option to "Classic Pivot Table Layout" and dragged the values so that they would be next to the items instead of across the top as shown:
The totals at the bottom for month 1, 2, and 3 are correct. The totals for each Item are correct. The grand total at the bottom shows the "% Error" with a divide by zero error. I am expecting it to be (40-30)/30=33.33%. If I ship any quantity of Item B in any month it calculates correctly. What do I have to do to get the correct value? Is this a feature or a bug?
Upvotes: 3
Views: 6326
Reputation: 604
So I can tell you what the problem is. I tried, but I cannot find a fix for it.
Basically you are looking at the final, Grand Total
for Total Sum of Percent Error
as still having the calculated field in it, however this is not the case.
For Month
's 1
, 2
, and 3
, you have the calculated field formula that you inserted is taking the values in Total Sum of Forecast
and Total Sum of Shipped
and is applying the calculation on the values in the those two cells above it to give you the Total Sum of % Error
.
What happens in the Grand Total
column is that it is updated by more than one formula, your calculated field formula, and the Sum
of the Grand Totals
for the Sum of % Error
for A
and the Sum of % Errors
for B
. If you click on the List Formulas
button, at least in Excel 2016, you get a new sheet that says this.
Calculated Field
Solve Order Field Formula
1 % Error =(Forecast-Shipped)/Shipped
Calculated Item
Solve Order Item Formula
Note: When a cell is updated by more than one formula,
the value is set by the formula with the last solve order.
To change formula solve orders,
use the Solve Order command on the PivotTable command bar.
The only problem is that you do not get the option to change the Solve Order for this, so the sum of the fields in the Grand Total
column override the calculation of (40-30)/30
Your option is that in the Design Tab, you can select Grand Totals
-> For Columns Only
, which will give you the totals at the bottom and then manually put the formulas into the Grand Total Column
that is now hidden. Sorry I can't come up with a more elegant solution.
If you are really ambitious about getting this to work with Pivot Tables
, many years ago I used to create them through VBA
and not using the built in GUI
, and you get much more control using the objects and methods than you do with the commands that are exposed to you in the user interface. Unfortunately most all of the knowledge on how to do that has been lost to time for me.
Upvotes: 1