addCalculatedMeasure(measure: Object)
[starting from version: 2.3]
Adds a calculated measure.
Note You can add calculated measure only for reports based on the "json", "csv", and "api" data source types.
Learn more about calculated measures in this guide: Calculated measures.
| Property/Type | Description |
|---|---|
| measure MeasureObject | The object that describes the calculated measure. Note that a calculated measure must have the formula property defined. |
In the example, we add the "Average Quantity" calculated measure. The formula is sum("Quantity")/count("Quantity"). The calculated measure will be added to the list of available measures and selected for the slice (active: true):
let measure = {
formula: 'sum("Quantity")/count("Quantity")',
uniqueName: "Average Quantity",
caption: "Average Quantity",
grandTotalCaption: "Total Quantity",
active: true
};
pivot.addCalculatedMeasure(measure);