Calculated values
Calculated values provide you with the possibility to add some measures missing in the original data. They can be saved and restored within the report. This feature is available for JSON, CSV and OCSV data sources.
Each calculated measure is described inside measure
object. It can have the following parameters:

uniqueName
– measure unique name, this property will be used as an identifier for the measure inside Pivot component and as the identifier to remove calculated measure via API. 
caption
(optional) – measure caption. 
formula
– string that represents the formula that can contain the following operations:+
,
,*
,/
; the following operators:isNaN()
,!isNaN()
; other measures can be addressed using measure unique name and aggregation function, for examplesum("Price")
ormax("Order")
. Pivot supports the following aggregation functions for CSV, OCSV and JSON data sources:"sum"
,"count"
,"distinctcount"
,"average"
,"product"
,"min"
,"max"
,"percent"
,"percentofcolumn"
,"percentofrow"
,"index"
,"difference"
,"%difference"
,"runningtotals"
. 
grandTotalCaption
(optional) – measure grand total caption. 
active
(optional) – boolean value that defines whether the calculated measure will be added to the list of available values but not selected (false
) or will be selected for the report (true
). 
individual
(optional) – Boolean. Defines whether the formula is calculated using raw values (true
) or using aggregated values (false
). Default value isfalse
. 
format
(optional) – number formatting name.
This example on JSFiddle illustrates how to define calculated measure with the minimal price for each color. You should define slice the following way:
slice: { rows: [ { uniqueName: "Color" } ], measures: [ { uniqueName: "Price", aggregation: "sum"}, { formula: 'min("Price")', uniqueName: "Min Price", caption: "Min Price", active: true } ] }
The next example illustrates how to define calculated measure with more complex formula. To highlight the values you can add conditional formatting for the Top Category
measure:
slice: { rows: [ { uniqueName: "Color" } ], measures: [ { uniqueName: "Price", aggregation: "sum"}, { uniqueName: "Top Category", formula: 'average("Price") < 4000 and sum("Quantity") > 100', caption: "Top Category", active: true } ] }, conditions: [ { formula: "#value = 1", measure: "Top Category", format: { backgroundColor: "#66FF99", color: "#000000", fontFamily: "Arial", fontSize: "12px" } } ]
This JSFiddle shows how you can specify number format for your calculated measure.
individual
property allows calculating the formula using raw values. In the example formula sum('Price') * sum('Amount')
will be calculated as following:
set individual: true
: 174 * 36 + 225 * 44
set individual: false
: (174 + 225) * (36 + 44)
The following report illustrates how to use individual
property:
{ dataSource: { data: [ { "Country" : "Canada", "Amount" : 36, "Price" : 174 }, { "Country" : "Canada", "Amount" : 44, "Price" : 225 } ] }, slice: { rows: [ { uniqueName: "Country" } ], measures: [ { uniqueName: "Price", aggregation: "sum", active: true }, { uniqueName: "Overall price", formula: "sum('Price') * sum('Amount')", individual: true, caption: "Overall price", active: true } ] } }
Add calculated values using Fields List
Please use Add calculated value
in Fields List to add calculated measure in run time.
Сalculated values via API
Calculated measures can be defined within the report or added via addCalculatedMeasure(measure:Object) API call. To remove calculated measure use removeCalculatedMeasure(measureName:String). removeAllCalculatedMeasures() removes all calculated measures.