Back to Devexpress

PivotCalculatedFieldCollection.Add(String) Method

officefileapi-devexpress-dot-spreadsheet-dot-pivotcalculatedfieldcollection-dot-add-x28-system-dot-string-x29.md

latest3.3 KB
Original Source

PivotCalculatedFieldCollection.Add(String) Method

Creates a new calculated field and appends it to the collection.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
PivotField Add(
    string formula
)
vb
Function Add(
    formula As String
) As PivotField

Parameters

NameTypeDescription
formulaString

The formula used to calculate field values.

|

Returns

TypeDescription
PivotField

The newly created calculated field.

|

Remarks

Use the Add method to add a calculated field to the PivotTable report. The default name (Field1, Field2, …) is assigned to the new field. Use the PivotField.Name property to rename the field.

A formula for the calculated field should conform to the common syntax rules and contain only supported elements:

  • In the formula, you can use constants and refer to other fields in the PivotTable report. Calculations are performed on the sum of the underlying data for any field in the formula. When you reference a field in your formula, you can enclose the field name in apostrophes or omit them.
  • You cannot create formulas that use a cell reference, defined name, circular references, or arrays.
  • You cannot use worksheet functions that require cell references or defined names as arguments.
  • The formula cannot refer to the PivotTable’s subtotals, totals, and Grand Total value.
  • The formula should use culture-dependent separators. Use the DocumentOptions.Culture property to specify the workbook culture.

After the calculated field is created, call the PivotTable.DataFields.Add method to add the field to the PivotTable’s data area.

Refer to the following topic for more information on how to create and modify calculated fields: How to: Create a Calculated Field.

See Also

Pivot Table API

How to: Create a Calculated Field

PivotCalculatedFieldCollection Interface

PivotCalculatedFieldCollection Members

DevExpress.Spreadsheet Namespace