Let's assume I have two columns in excel, dates as rows and I want to create a pivot table with some calculated field. Formula for calculated field is Column1 / AVERAGE(Column2)
, depending on dates selected.
I use vba. but when I do
pvtTable.CalculatedFields.Add Name:="Test1", Formula:="Column1 / AVERAGE(Column2)"
EDIT: AVERAGE
is being count from sum of values in column 2 (for selected date range), not single values. AVERAGE
seems to be ignored in calculated field's formula and sum is taken instead.
Is there any way to use single values when using AVERAGE
in calculated field's formula? I use Office 2010.
More details
I tried to do this:
With pvtTable
With .PivotFields("Column2")
.Orientation = xlDataField
.Function = xlAverage
.NumberFormat = "0.00"
.Value = "Avg Column2"
End With
End With
pvtTable.CalculatedFields.Add Name:="Test2", Formula:="Column1 / Avg Column2"
But Test2
isn't shown on the pivot table's field list. When I want to display it from vba, I get an error Unable to get the PivotFields property of the PivotTable class
.