.NET Framework 4.5.2+
.NET Framework 4.5.2+
.NET Standard 2.0+
Row

PivotField.Formula Property

Gets or sets the formula for the calculated field.

Namespace: DevExpress.Spreadsheet

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

Declaration

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

Property Value

Type Description
String

A String value that is the calculated field's formula.

Remarks

Use the Formula property to modify the formula of the existing calculated field. To add a calculated field to a pivot table, use the PivotCalculatedFieldCollection.Add method of the PivotTable.CalculatedFields collection.

Dim worksheet As Worksheet = workbook.Worksheets("Report1")
workbook.Worksheets.ActiveWorksheet = worksheet

' Access the pivot table by its name in the collection.
Dim pivotTable As PivotTable = worksheet.PivotTables("PivotTable1")
' Create a calculated field based on data in the "Sales" field.
pivotTable.CalculatedFields.Add("=Sales*10%", "Sales Tax Rate 10")
' Access the calculated field by its name in the collection.
Dim field As PivotField = pivotTable.CalculatedFields("Sales Tax Rate 10")
'Change the formula for the calculated field.
field.Formula = "=Sales*15%"
'Change the calculated field name.
field.Name = "Sales Tax Rate 15"
'Add the calculated field to the data area and specify the custom field name.
Dim dataField As PivotDataField = pivotTable.DataFields.Add(field, "Total Tax")
' Specify the number format for the data field.
dataField.NumberFormat = "_([$$-409]* #,##0.00_);_([$$-409]* (#,##0.00);_([$$-409]* "" - ""??_);_(@_)"

For the pivot fields that originate from the source data, the Formula property returns an empty string.

See Also