Back to Devexpress

PivotItem.Formula Property

officefileapi-devexpress-dot-spreadsheet-dot-pivotitem-857ff761.md

latest6.3 KB
Original Source

PivotItem.Formula Property

Gets or sets the formula for the calculated item.

Namespace : DevExpress.Spreadsheet

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

NuGet Package : DevExpress.Spreadsheet.Core

Declaration

csharp
string Formula { get; set; }
vb
Property Formula As String

Property Value

TypeDescription
String

A String value that is the calculated item’s formula.

|

Remarks

Use the Formula property to modify the formula of the existing calculated item. To add a calculated item to a specific field, use the PivotCalculatedItemCollection.Add method of the PivotField.CalculatedItems collection.

View Example

csharp
Worksheet worksheet = workbook.Worksheets["Report7"];
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["Customer"];

// Add a calculated item to the "Customer" field.
PivotItem item = field.CalculatedItems.Add("='Big Foods'*110%", "Big Foods Sales Plan");

//Change the formula for the calculated item.
item.Formula = "='Big Foods'*115%";
vb
Dim worksheet As Worksheet = workbook.Worksheets("Report7")
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("Customer")

' Add a calculated item to the "Customer" field.
Dim item As PivotItem = field.CalculatedItems.Add("='Big Foods'*110%", "Big Foods Sales Plan")

'Change the formula for the calculated item.
item.Formula = "='Big Foods'*115%"

For the field items that originate from the source data, the Formula property returns an empty string.

The following code snippets (auto-collected from DevExpress Examples) contain references to the Formula 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.

wpf-spreadsheet-pivot-table-api-examples/CS/SpreadsheetWPFPivotTableExamples/CodeExamples/PivotCalculatedItemActions.cs#L61

csharp
//Change the formula for the calculated item.
item.Formula = "='Big Foods'*115%";
#endregion #ModifyCalculatedItem

winforms-spreadsheet-pivot-table-api/CS/SpreadsheetPivotTableExamples/CodeExamples/PivotCalculatedItemActions.cs#L61

csharp
//Change the formula for the calculated item.
item.Formula = "='Big Foods'*115%";
#endregion #ModifyCalculatedItem

spreadsheet-document-api-pivot-table-examples/CS/SpreadsheetDocServerPivotAPI/CodeExamples/PivotCalculatedItemActions.cs#L67

csharp
//Change the formula for the calculated item.
item.Formula = "='Big Foods'*115%";
#endregion #ModifyCalculatedItem

wpf-spreadsheet-pivot-table-api-examples/VB/SpreadsheetWPFPivotTableExamples/CodeExamples/PivotCalculatedItemActions.vb#L56

vb
'Change the formula for the calculated item.
            item.Formula = "='Big Foods'*115%"
' #End Region ' #ModifyCalculatedItem

winforms-spreadsheet-pivot-table-api/VB/SpreadsheetPivotTableExamples/CodeExamples/PivotCalculatedItemActions.vb#L56

vb
'Change the formula for the calculated item.
            item.Formula = "='Big Foods'*115%"
' #End Region ' #ModifyCalculatedItem

spreadsheet-document-api-pivot-table-examples/VB/SpreadsheetDocServerPivotAPI/CodeExamples/PivotCalculatedItemActions.vb#L62

vb
'Change the formula for the calculated item.
            item.Formula = "='Big Foods'*115%"
#End Region ' #ModifyCalculatedItem

See Also

Add

PivotItem Interface

PivotItem Members

DevExpress.Spreadsheet Namespace