1

I'm attempting to create a pivot table through the Excel Javascript API, based off of some old code. With VBA, I could write something like

Worksheets(1).PivotTables(1).CalculatedFields.Add "PxS", _ 
 "= Product * Sales"

to add a calculated field to a pivot table. I can't find an equivalent through the excel javascript api and I'm not sure if it just hasn't been added yet, or if I'm missing a feature somewhere.

The closest thing I've found is ShowAsRule, but I don't think the functionality there is equivalent (you can't use a custom formula)

Eugene Astafiev
  • 47,483
  • 3
  • 24
  • 45
plckrt
  • 11
  • 2

1 Answers1

0

can you check the doc of Add rows and columns to a PivotTable segment in the url https://learn.microsoft.com/en-us/office/dev/add-ins/excel/excel-add-ins-pivottables ? A workaround is creating a new column with like C=A*B, and add C directly

Rita
  • 72
  • 3
  • The problem with this is how fields are aggregated in a pivot table. So if I calculate something like a percentage at a bottom level of the hierarchy, at the top level it will be > 100% but that metric won't be accurate. – plckrt Oct 14 '22 at 17:31