Skip to main content
A newer version of this page is available. .
.NET Framework 4.5.2+
Row

PivotDataFieldCollection.Add(PivotField, String) Method

Adds a field to the data area of the pivot table.

Namespace: DevExpress.Spreadsheet

Assembly: DevExpress.Spreadsheet.v19.1.Core.dll

Declaration

PivotDataField Add(
    PivotField field,
    string name
)

Parameters

Name Type Description
field PivotField

A PivotField object specifying a pivot field that should be added to the data area of the PivotTable report.

name String

A String value that specifies the data field name in the pivot table. This value is assigned to the PivotDataField.Name property.

Returns

Type Description
PivotDataField

A PivotDataField object which represents the inserted data field.

Remarks

To add a new field to the data area of the PivotTable report at the specified position, use the PivotDataFieldCollection.Insert method. Afterwards, you can re-order fields in the data area using the MoveDown, MoveUp, MoveToBeginning or MoveToEnd method of the PivotDataField object whose position you wish to change. You can also change the orientation of multiple data fields in the report using the PivotLayout.DataOnRows property.

To change the default summary function used by a specific data field, use the PivotDataField.SummarizeValuesBy property. To apply an additional calculation option to a data field and change the way summary values are displayed within the field, use the PivotDataField.ShowValuesWithCalculation method overloads.

To remove a data field from the collection, use the PivotDataFieldCollection.Remove or PivotDataFieldCollection.RemoveAt method. You can also use the PivotDataFieldCollection.Clear method to remove all fields from the PivotTable’s data area.

Example

Dim sourceWorksheet As Worksheet = workbook.Worksheets("Data1")
Dim worksheet As Worksheet = workbook.Worksheets.Add()
workbook.Worksheets.ActiveWorksheet = worksheet

' Create a pivot table.
Dim pivotTable As PivotTable = worksheet.PivotTables.Add(sourceWorksheet("A1:D41"), worksheet("B2"))

' Add the "Product" field to the row axis area.
pivotTable.RowFields.Add(pivotTable.Fields("Product"))
' Add the "Category" field to the column axis area.
pivotTable.ColumnFields.Add(pivotTable.Fields("Category"))
' Add the "Sales" field to the data area and specify the custom field name.
Dim dataField As PivotDataField = pivotTable.DataFields.Add(pivotTable.Fields("Sales"), "Sales(Sum)")
' Specify the number format for the "Sales" field.
dataField.NumberFormat = "_([$$-409]* #,##0.00_);_([$$-409]* (#,##0.00);_([$$-409]* "" - ""??_);_(@_)"
' Add the "Region" field to the filter area.
pivotTable.PageFields.Add(pivotTable.Fields("Region"))

The following code snippets (auto-collected from DevExpress Examples) contain references to the Add(PivotField, String) 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.

See Also