Adding Calculated Value inline code

Can anyone create a jsfiddle showing up to create a calculated field
for example

var report = {
configuratorActive: false,
data: jsondata,
rows: [{uniqueName: “Color”}],
columns: [{uniqueName: “[Measures]”}],
measures: [{uniqueName: “Price”}, {uniqueName: “Quantity”}],
addCalculatedValue: [……]

formats: [{name: “”, nullValue: “blank”}],
showHeaders: false

5 answers

Iryna Kulchytska Staff March 1, 2016

Hello David,

Here is a jsfiddle that addresses your question:
Calculated fields go in ‘measures’ array with all the measures, as follows:
measures: [{uniqueName: “Price”, aggregation: “average”, availableAggregations: [“average”], active: true}, {uniqueName: “Quantity”, aggregation: “average”, availableAggregations: [“average”]}, {uniqueName: “Formula #1”, caption: “Formula #1”, calculated: true, formula: “sum(‘Price’) / sum(‘Quantity’)”, active: true}]
Kind regards,

Public March 1, 2016

Thanks. How do I sort a variable in the column descending?

Iryna Kulchytska Staff March 1, 2016

Hi David,
You can sort values in some column by specifying measure, tuple and type in columnSorting property as follows:

columnSorting: {measure: "Price", tuple: "", type: "desc"}

Here is a jsfiddle:
Please let me know if it is what you are looking for.
Kind regards,

Public March 1, 2016

so if I want to sort Color first then another row, it would be

columnSorting: [ {measure: "SortFirstVariable", tuple: "", type: "desc"},{measure: "ThenSortSecondVariable", tuple: "", type: "desc"} ]
Iryna Kulchytska Staff March 1, 2016

Thank you for your question.
If you want to sort colors in Color field, then you can do this from report object the following way:

rows: [{uniqueName: "Color", sortName: "desc"}]

The previous example is about the case when you want to sort numbers in columns on the grid. 
Also, please note that the sorting can be done from UI. Then you can call flexmonster.getReport() API call to get the report object with all the settings and you can examine it to find out how the change from UI is stored in the report object.
Please let me know if you need more clarifications.
Kind regards,

Please login or Register to Submit Answer