CalculatedField in Pivot Table


Posted by Bill on March 14, 2001 5:26 AM

My data has price, quantity sold, quantity on hand, quantity on order, etc.

I have a VBA macro that produces a pivot table which shows these quantities by department.

I want to modify the pivot table to show each of the quantities times the unit price.

The following code runs:
PT.CalculatedFields.Add "DOrd", "=Price*Ord"

But to my surprise, the pivot table first adds up all the quantities for the department, then adds up all the prices for the department, then multiplies these sums together, producing a ridiculous result.

Is there any way to do this calculation correctly in the pivot table?

I realize I could add eight more fields to my table in excel and do the calculation before creating the pivot table.

Thanks in advance,

Bill



Posted by Mark W. on March 14, 2001 6:21 AM

Bill, quoting from the Excel Help topic for
"Syntax for calculated field and item formulas
in PivotTables", "Formulas for calculated fields
operate on the sum of the underlying data for any
fields in the formula."

If your data set contained both the order quantity
and the sales amount and you could produce the
average price by department using a Calculated
Field.