Add calculated field in Pivot Table with Golang via C++
Contents
[
Hide
]
Possible Usage Scenarios
When you create a pivot table based on known data, you may find that the data in it is not what you want. The data you need is a combination of the original data. For example, you may need to add, subtract, multiply, or divide the original data before obtaining the desired results. In such cases, you need to create a calculated field and set the corresponding formula for the calculation, then perform some statistical and other operations on the calculated field.
Add calculated field in Pivot Table in Excel
Insert a calculated field in a PivotTable in Excel, follow these steps:
- Select the PivotTable that you want to add a calculated field to.
- Go to the PivotTable Analyze tab on the ribbon.
- Click on “Fields, Items, & Sets” and then select “Calculated Field” from the drop-down menu.
- In the “Name” field, enter a name for the calculated field.
- In the “Formula” field, enter the formula for the calculation you want to perform using the appropriate PivotTable field names and mathematical operators.

- Click OK to create the calculated field.
- The new calculated field will appear in the PivotTable Field List under the Values section.
- Drag the calculated field to the Values section of the PivotTable to display the calculated values.

Add calculated field in Pivot Table Using C++
Add a calculated field to an Excel file using Aspose.Cells. Please see the following sample code. After executing the example code, a pivot table with a calculated field is added to the worksheet.
- Set the original data and create a pivot table.
- Create the calculated field according to the existing PivotField in the pivot table.
- Add the calculated field to the data area.
- Finally, it saves the workbook in the output XLSX format.