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

PivotTable.CalculatedFields Property

Provides access to the collection of calculated fields in the specified PivotTable report.

Namespace: DevExpress.Spreadsheet

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

Declaration

PivotCalculatedFieldCollection CalculatedFields { get; }

Property Value

Type Description
PivotCalculatedFieldCollection

A PivotCalculatedFieldCollection object specifying the PivotTable’s collection of calculated fields.

Remarks

Use the CalculatedFields property to get access to the collection that stores all calculated fields added to the PivotTable report. An individual calculated field can be accessed by its index or name in the collection.

To add a calculated field to the pivot table, use the PivotCalculatedFieldCollection.Add method.

Important

Calculated fields are stored in the PivotCache and available to all pivot tables that share the same cache.

To remove a calculated field from the PivotTable report, use the PivotCalculatedFieldCollection.Remove or PivotCalculatedFieldCollection.RemoveAt method. You can also use the PivotCalculatedFieldCollection.Clear method to remove all calculated fields from the collection at once.

Example

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")
' Create a calculated field based on data in the "Sales" field.
Dim field As PivotField = pivotTable.CalculatedFields.Add("=Sales*10%", "Sales Tax")
' Add the calculated field to the data area and specify the custom field name.
Dim dataField As PivotDataField = pivotTable.DataFields.Add(field, "Total Tax")
' Specify the number format for the data field.
dataField.NumberFormat = "_([$$-409]* #,##0.00_);_([$$-409]* (#,##0.00);_([$$-409]* "" - ""??_);_(@_)"

The following code snippets (auto-collected from DevExpress Examples) contain references to the CalculatedFields property.

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