Webdatarocks Reportsetup: How to show multiple aggregations for the same attribute ('unique name')

77 Views Asked by At

Let's say my datasource shows price and quantity of different products grouped by product type.

Is it possible to show two columns per attribute (two for price and two for quantity), where one is showing the average and the other one is showing the stdevs?

1

There are 1 best solutions below

0
solja On

You can add a second aggregation for each value field as a calculated value:

measures: [{
          uniqueName: "Price",
          aggregation: "stdevs",
          caption: "STDEV of Price"
        },
        {
          uniqueName: "PriceAverage",
          formula: "average('Price')",
          caption: "Average of Price"
        }]

Here is a full example in the snippet:

var pivot = new WebDataRocks({
  container: "#wdr-component",
  toolbar: true,
  report: {
    dataSource: {
      dataSourceType: "csv",
      filename: "https://cdn.webdatarocks.com/data/data.csv"
    },
    options: {
      showAggregationLabels: false
    },
    slice: {
      rows: [{
        "uniqueName": "Category"
      }],
      columns: [{
        "uniqueName": "Measures"
      }],
      measures: [{
          uniqueName: "Price",
          aggregation: "stdevs",
          caption: "STDEV of Price"
        },
        {
          uniqueName: "PriceAverage",
          formula: "average('Price')",
          caption: "Average of Price"
        },
        {
          uniqueName: "Quantity",
          aggregation: "stdevs",
          caption: "STDEV of Quantity"
        },
        {   uniqueName: "QuantityAverage",
          formula: "average('Quantity')",
          caption: "Average of Quantity"
        },
      ]
    },
    formats: [{
      name: "", //default format
      decimalPlaces: 2,
      currencySymbol: "$",
      currencySymbolAlign: "left"
    }]
  }
});
<link href="https://cdn.webdatarocks.com/latest/webdatarocks.min.css" rel="stylesheet"/>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.toolbar.min.js"></script>
<script src="https://cdn.webdatarocks.com/latest/webdatarocks.js"></script>

<div id="wdr-component"></div>