Back to Devexpress

PivotField.SetSubtotal(PivotSubtotalFunctions) Method

officefileapi-devexpress-dot-spreadsheet-dot-pivotfield-dot-setsubtotal-x28-devexpress-dot-spreadsheet-dot-pivotsubtotalfunctions-x29.md

latest6.6 KB
Original Source

PivotField.SetSubtotal(PivotSubtotalFunctions) Method

Specifies the function(s) to calculate subtotals for the PivotTable field.

Namespace : DevExpress.Spreadsheet

Assembly : DevExpress.Spreadsheet.v25.2.Core.dll

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
void SetSubtotal(
    PivotSubtotalFunctions type
)
vb
Sub SetSubtotal(
    type As PivotSubtotalFunctions
)

Parameters

NameTypeDescription
typePivotSubtotalFunctions

The PivotSubtotalFunctions enumeration members specifying one or more functions used to calculate subtotals for the field.

|

Remarks

Use the SetSubtotal method to change the default summary calculation or to show more than one type of subtotal for a given PivotField, currently shown as an outer row or column field in the report.

The following example demonstrates how to use multiple functions to subtotal the “Category” row field. To do this, combine the required PivotSubtotalFunctions enumeration values with a bitwise OR operator.

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"];
// Access the pivot field by its name in the collection.
PivotField field = pivotTable.Fields["Category"];
// Display multiple subtotals for the field.  
field.SetSubtotal(PivotSubtotalFunctions.Sum | PivotSubtotalFunctions.Average);
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")
' Access the pivot field by its name in the collection.
Dim field As PivotField = pivotTable.Fields("Category")
' Display multiple subtotals for the field.  
field.SetSubtotal(PivotSubtotalFunctions.Sum Or PivotSubtotalFunctions.Average)

To use the default function to calculate a subtotal for a particular outer field, use the field’s PivotField.SetSubtotalAutomatic method.

Use the PivotField.SubtotalType property to obtain the type of subtotal displayed for a PivotTable field. To get the function(s) used to calculated the field’s subtotals, use the PivotField.SubtotalFunctions property.

The following code snippets (auto-collected from DevExpress Examples) contain references to the SetSubtotal(PivotSubtotalFunctions) method.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-spreadsheet-pivot-table-api/CS/SpreadsheetPivotTableExamples/CodeExamples/PivotFieldActions.cs#L141

csharp
// Display multiple subtotals for the field.
field.SetSubtotal(PivotSubtotalFunctions.Sum | PivotSubtotalFunctions.Average);
#endregion #MultipleSubtotals

spreadsheet-document-api-pivot-table-examples/CS/SpreadsheetDocServerPivotAPI/CodeExamples/PivotFieldActions.cs#L153

csharp
// Display multiple subtotals for the field.
field.SetSubtotal(PivotSubtotalFunctions.Sum | PivotSubtotalFunctions.Average);
#endregion #MultipleSubtotals

winforms-spreadsheet-pivot-table-api/VB/SpreadsheetPivotTableExamples/CodeExamples/PivotFieldActions.vb#L134

vb
' Display multiple subtotals for the field.
field.SetSubtotal(PivotSubtotalFunctions.Sum Or PivotSubtotalFunctions.Average)
' #End Region ' #MultipleSubtotals

spreadsheet-document-api-pivot-table-examples/VB/SpreadsheetDocServerPivotAPI/CodeExamples/PivotFieldActions.vb#L142

vb
' Display multiple subtotals for the field.
            field.SetSubtotal(PivotSubtotalFunctions.Sum Or PivotSubtotalFunctions.Average)
#End Region ' #MultipleSubtotals

See Also

SetSubtotalAutomatic()

SubtotalType

SubtotalFunctions

PivotField Interface

PivotField Members

DevExpress.Spreadsheet Namespace