Skip to main content
Row

PivotTable.CalculatedFields Property

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

Namespace: DevExpress.Spreadsheet

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

NuGet Package: DevExpress.Spreadsheet.Core

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

View Example

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

// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];
// Create a calculated field based on data in the "Sales" field.
PivotField field = pivotTable.CalculatedFields.Add("=Sales*10%", "Sales Tax");
// Add the calculated field to the data area and specify the custom field name.
PivotDataField dataField = 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