PivotCalculatedItemCollection.Add(String, String) Method
Creates a new calculated item and appends it to the collection.
A String value that specifies the formula for the item.
A String value that specifies the name of the item.
A PivotItem object that specifies the newly created calculated item.
Use the Add method to add a calculated item to a PivotTable field. A calculated item uses a formula to calculate its value based on values of other items in the same field where the calculated item resides.
The following code demonstrates how to create two calculated items to calculate total sales for each region.
A complete sample project is available at https://github.com/DevExpress-Examples/winforms-spreadsheet-pivot-table-api-t298650
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")
For details on how to insert and modify calculated items, refer to the How to: Create a Calculated Item example.