Back to Devexpress

How to: Display or Hide Grand Totals for a Pivot Table

windowsforms-115412-controls-and-libraries-spreadsheet-examples-pivot-tables-how-to-display-or-hide-grand-totals-for-a-pivot-table.md

latest3.4 KB
Original Source

How to: Display or Hide Grand Totals for a Pivot Table

  • Jun 11, 2023
  • 2 minutes to read

To control how grand totals are displayed in a pivot table, use the following properties.

PropertyDescription
PivotLayout.ShowRowGrandTotalsSpecifies whether to display a grand total column.
PivotLayout.ShowColumnGrandTotalsSpecifies whether to display a grand total row.
PivotViewOptions.GrandTotalCaptionSpecifies the text label for both the grand total column and grand total row.

Hide Grand Totals for Rows

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Report1"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Add the "Region" field to the column axis area. 
pivotTable.ColumnFields.Add(pivotTable.Fields["Region"]);

// Hide grand totals for rows.
pivotTable.Layout.ShowRowGrandTotals = false;
vb
Dim worksheet As Worksheet = workbook.Worksheets("Report1")
workbook.Worksheets.ActiveWorksheet = worksheet

' Access the pivot table by its name in the collection.
Dim pivotTable As PivotTable = worksheet.PivotTables("PivotTable1")
' Add the "Region" field to the column axis area. 
pivotTable.ColumnFields.Add(pivotTable.Fields("Region"))

' Hide grand totals for rows.
pivotTable.Layout.ShowRowGrandTotals = False

The image below shows the resulting PivotTable report.

Hide Grand Totals for Columns

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Report1"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Add the "Region" field to the column axis area. 
pivotTable.ColumnFields.Add(pivotTable.Fields["Region"]);

// Hide grand totals for columns.
pivotTable.Layout.ShowColumnGrandTotals = false;
vb
Dim worksheet As Worksheet = workbook.Worksheets("Report1")
workbook.Worksheets.ActiveWorksheet = worksheet

' Access the pivot table by its name in the collection.
Dim pivotTable As PivotTable = worksheet.PivotTables("PivotTable1")
' Add the "Region" field to the column axis area. 
pivotTable.ColumnFields.Add(pivotTable.Fields("Region"))

' Hide grand totals for columns.
pivotTable.Layout.ShowColumnGrandTotals = False

The image below shows the resulting PivotTable report.