Menu
Download Free Trial
  1. Getting started
    1. Quickstart
    2. System requirements
    3. Managing license keys
    4. Updating to the latest version
    5. Typical errors
    6. Migration guide
    7. Installation troubleshooting
  2. JSON data source
    1. Data types in JSON
  3. CSV data source
    1. Data types in CSV
  4. Connecting to SQL database
    1. Connecting to database with .NET
    2. Connecting to Relational Database with .NET Core
    3. Connecting to database with Java
    4. Connecting to database with PHP
  5. Connecting to Microsoft Analysis Services
    1. Getting started with Accelerator
    2. Installing Accelerator as a Windows Service
    3. Configuring username/password protection
    4. Configuring secure HTTPS connection
    5. Troubleshooting
  6. Connecting to Pentaho Mondrian
    1. Getting started with Accelerator
    2. Configuring Mondrian roles
    3. Сonfiguring username/password protection
    4. Сonfiguring secure HTTPS connection
    5. Troubleshooting
  7. Connecting to icCube
  8. Configuring report
    1. Data source
    2. Slice
    3. Options
    4. Number formatting
    5. Conditional formatting
    6. Set report to the component
    7. Get report from the component
    8. Date and time formatting
    9. Calculated values
    10. Custom sorting
  9. Integration
    1. Integration with AngularJS
    2. Integration with Angular 2
    3. Integration with Angular 4
    4. Integration with React
    5. Integration with RequireJS
    6. Integration with TypeScript
    7. Integration with ASP.NET
    8. Integration with JSP
    9. Integration with PhoneGap
  10. Integration with charts
    1. Integration with Highcharts
    2. Integration with FusionCharts
    3. Integration with Google Charts
    4. Integration with any charting library
  11. Customizing toolbar
  12. Customizing appearance
  13. Localizing component
  14. Global Object
  15. Export and print
  16. API reference - JavaScript
  17. API reference - Flex
Table of contents

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 example sum("Price") or max("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".
  • 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 is false.
  • 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: "if(#value = 1, 'trueStyle')",
        measure: "Top Category",
        trueStyle: {
            backgroundColor: "#66FF99",
            color: "#000000",
            fontFamily: "Arial",
            fontSize: 12
        }
    }
]

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
		    }
		]
	},
	options: {
		configuratorActive: false
	}
}

Add calculated values using Fields List

Please use Add calculated value in Fields List to add calculated measure in run time.

addcalculatedvalue

С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.