If a pivot table has a calculated field and I import new data and refresh the pivot table, the references in the formula for the calculated field is changed and hence becomes invalid. If I remove the calculated field all is good.
Before/after screenshot
2019-03-27_12-13-38.png (201.7 KB)
Template
I can send the template Excel file with the calculated field (can’t upload it here).
Code
Data import:
dataSheet.Cells.ImportData(data, 0, 0, new ImportTableOptions {DateFormat = "dd-MMM-yyyy HH:mm"});
Pivot table refresh:
foreach (var worksheet in workbook.Worksheets)
{
if (!worksheet.PivotTables.Any()) continue;
foreach (var pt in worksheet.PivotTables)
{
pt.RefreshData();
pt.CalculateData();
}
}
I also tried, without luck, to add the calculated field in code:
var pt = workbook.Worksheets[“Reports by manager”].PivotTables[“ptByManager”];
pt?.AddCalculatedField(“Status”, “= SUM(‘Report’) / (SUM(‘Report’) + SUM(‘NoReport’)) * 100”, true);
Two questions:
How can Aspose.Cells handle pivot tables with calculated fields?
What should the formula in the AddCalculatedField look like?
Thanks in advance.
Regards
Morten