Change the aggregation from count to sum in pivot table using microsoft interop excel in C#

33 Views Asked by At

In my Pivot table, I have a data field which I want to be summarized as sum. I tried changing the subtotalfunction property to sum, but it is creating a new value called "sum of Amount" along with the original Amount value in the pivot table. But I want to change the original Amount value aggregation to sum instead of count and I don't want to create a new one.

Excel.PivotField valueField =     pivotTable.PivotFields("Amount");
valueField.Orientation =  Excel.XlPivotFieldOrientation.xlDataField;
valueField.Function = Excel.XlConsolidationFunction.xlSum;

Can someone give me an example of how I can do this?

I'm using Microsoft Interop Excel.

Thanks so much :)

0

There are 0 best solutions below