I am not able to move the grand total of values from the row section to the column section. I have provided a sample xlsx file and the general code(doesn’t exactly match the file provided but it is the same idea).
The 2nd tab is what the code is creating. The 3rd tab is what I need. I am not sure why I am getting the Summation values in the rows section anyway…
This is a picture of what I need to do
pivot-what-i-need.PNG (10.0 KB)
PivotTableCollection pivotTables = pivotTableSheet.PivotTables;
string pivotSource = $"='{ratingOverviewSheet.Name}'!A1:D{workingRow}";
int pivotTableIndex = pivotTables.Add(pivotSource, pivotTableDestCellName, pivotTableName);
var thePivotTable = pivotTables[pivotTableIndex];
thePivotTable.PivotTableStyleType = PivotTableStyleType.PivotTableStyleMedium9;
thePivotTable.AddFieldToArea(PivotFieldType.Row, 0);
thePivotTable.AddFieldToArea(PivotFieldType.Data, 1);
thePivotTable.AddFieldToArea(PivotFieldType.Data, 2);
thePivotTable.AddFieldToArea(PivotFieldType.Page, 3);
thePivotTable.ColumnGrand = true;
thePivotTable.RowGrand = true;
thePivotTable.ShowValuesRow = true;
//Filter by category
PivotField pf = thePivotTable.BaseFields["Category"];
thePivotTable.PageFields.Add(pf);
PivotField pivotField = thePivotTable.PageFields[0];
int pageItemCount = pivotField.PivotItems.Count;
for (int i = 0; i < pageItemCount; i++)
{
if (itemCategory.Equals(pivotField.PivotItems[i].Value))
{
pivotField.CurrentPageItem = (short)i;
}
}
int chartIndex = pivotTableSheet.Charts.Add(ChartType.Bar3DClustered, 0, 0, chartBottomRow, 26);
pivotTableSheet.Charts[chartIndex].PivotSource = $"{pivotTableSheet.Name}!{pivotTableName}";