Back to Devexpress

PivotCalculatedItemCollection.Add(String) Method

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

latest3.5 KB
Original Source

PivotCalculatedItemCollection.Add(String) Method

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

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

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

Parameters

NameTypeDescription
formulaString

A String value that specifies the formula for the item.

|

Returns

TypeDescription
PivotItem

A PivotItem object that specifies the newly created calculated item.

|

Remarks

Use the Add method to add a calculated item to a PivotTable field. The default name (Formula1, Formula2, etc.) will be automatically assigned to the calculated item. To rename the item, use the PivotItem.Caption property.

For more information on how to insert and modify calculated items, refer to the How to: Create a Calculated Item example.

Example

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Report10"];
workbook.Worksheets.ActiveWorksheet = worksheet;

// Access the pivot table by its name in the collection.
PivotTable pivotTable = worksheet.PivotTables["PivotTable1"];

// Access the pivot field by its name in the collection.
PivotField field = pivotTable.Fields["State"];

// Add calculated items to the "State" field.
field.CalculatedItems.Add("=Arizona+California+Colorado", "West Total");
field.CalculatedItems.Add("=Illinois+Kansas+Wisconsin", "Midwest Total");
vb
Dim worksheet As Worksheet = workbook.Worksheets("Report10")
workbook.Worksheets.ActiveWorksheet = worksheet

' Access the pivot table by its name in the collection.
Dim pivotTable As PivotTable = worksheet.PivotTables("PivotTable1")

' Access the pivot field by its name in the collection.
Dim field As PivotField = pivotTable.Fields("State")

' Add calculated items to the "State" field.
field.CalculatedItems.Add("=Arizona+California+Colorado", "West Total")
field.CalculatedItems.Add("=Illinois+Kansas+Wisconsin", "Midwest Total")

See Also

How to: Create a Calculated Item

PivotCalculatedItemCollection Interface

PivotCalculatedItemCollection Members

DevExpress.Spreadsheet Namespace