Median aggregation
Slice configuration
by Flexmonster Pivot Table
November 24, 2025
HTML
<script src="https://cdn.flexmonster.com/flexmonster.js"></script>
<p>
In this example, the <code>"median"</code> aggregation is used to calculate
the median of prices depending on a country and a color.
</p>
<div id="pivot-container"></div>
CSS
@import url(https://cdn.flexmonster.com/assets/jsfiddle-styles.css);
JavaScript
const pivot = new Flexmonster({
container: "pivot-container",
componentFolder: "https://cdn.flexmonster.com/",
report: {
dataSource: {
data: getData()
},
slice: {
rows: [{
uniqueName: "Country"
}],
columns: [{
uniqueName: "Color"
}, {
uniqueName: "[Measures]"
}],
measures: [{
uniqueName: "Price",
aggregation: "median"
}]
},
formats: [{
name: "",
decimalSeparator: ".",
decimalPlaces: 2,
nullValue: "-"
}]
}
});
function getData() {
return [
{
"Color" : "green",
"Country" : "Canada",
"City" : "Toronto",
"Price" : 174,
"Quantity" : 22
},
{
"Color" : "red",
"Country" : "USA",
"City" : "Los Angeles",
"Price" : 166,
"Quantity" : 19
},
{
"Color" : "blue",
"Country" : "USA",
"City" : "Tallahassee",
"Price" : 215,
"Quantity" : 25
},
{
"Color" : "black",
"Country" : "Canada",
"City" : "Montreal",
"Price" : 194,
"Quantity" : 15
},
{
"Color" : "red",
"Country" : "Canada",
"City" : "Montreal",
"Price" : 123,
"Quantity" : 12
},
{
"Color" : "blue",
"Country" : "Canada",
"City" : "Toronto",
"Price" : 189,
"Quantity" : 31
},
{
"Color" : "black",
"Country" : "USA",
"City" : "New York",
"Price" : 312,
"Quantity" : 32
},
{
"Color" : "black",
"Country" : "USA",
"City" : "New York",
"Price" : 246,
"Quantity" : 21
},
{
"Color" : "black",
"Country" : "Canada",
"City" : "Ontario",
"Price" : 241,
"Quantity" : 20
},
{
"Color" : "black",
"Country" : "Canada",
"City" : "Toronto",
"Price"...