'How do i change a pivot table from grand total to average?
Good afternoon, it is necessary that in the end there is not a sum, but the average of all values. Is it possible to implement this functionality?
Solution 1:[1]
In WDR, there is no clear way to make an average grand total if subtotal values contain the sum aggregations. But you can change the text in grand total cells with the customizeCell function to make it contain an average value. Example:
<!DOCTYPE html>
<html>
<head>
<title>WDR</title>
</head>
<body>
<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"></div>
<script>
var pivot = new WebDataRocks({
container: "#wdr",
toolbar: true,
customizeCell: customize,
report: {
dataSource: {
filename: "https://cdn.webdatarocks.com/data/data.csv"
}
}
});
function customize(cell,data) {
if(data.isGrandTotalRow) {
cell.text = data.value / (data.rowIndex - 1);
}
}
</script>
</body>
</html>
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Maxym Diachenko |
