Skip to main content
Row

PivotDataField Interface

Represents a reference to a PivotField object that is currently shown as a data field.

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

Declaration

public interface PivotDataField :
    PivotFieldReferenceBase

Remarks

The PivotDataField object is a member of the PivotDataFieldCollection collection, which stores all data fields of a PivotTable report. An individual PivotDataField object can be accessed by its name or index in the collection using the PivotDataFieldCollection.Item property.

To add a PivotField to the data area of the PivotTable report, use the PivotDataFieldCollection.Add method. To change the default summary function used by the data field, use the PivotDataField.SummarizeValuesBy property. To apply an additional calculation option to the data field and change the way summary values are displayed within the field, use the PivotDataField.ShowValuesWithCalculation method overloads. To apply a number format to the data field, use the PivotDataField.NumberFormat property.

View 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"))

To change the position of a field within the data area, use the PivotDataField‘s PivotFieldReferenceBase.MoveDown, PivotFieldReferenceBase.MoveUp, PivotFieldReferenceBase.MoveToBeginning or PivotFieldReferenceBase.MoveToEnd method.

To remove a data field from the pivot table, use the PivotDataFieldCollection.Remove or PivotDataFieldCollection.RemoveAt method.

See Also