Closed EwetoyeIbrahim closed 4 years ago
Thank you, I never knew it could be this cheap, valueList did the trick (SO link):
function categ_tab(data){
// The needed data should be grouped by names summed up by qty and price
// Thus crossfilter and reductio will be used to take the burden off server
var group = crossfilter(data).dimension(function(d) { return d.name; }).group(),
reducer = reductio();
// sum up qty and price
reducer.value("qty").sum(function(d) { return d.qty_sum; });
reducer.value("price").sum(function(d) { return d.price_sum; });
reducer.value("category").valueList(function (d) { return d.category;});
return reducer(group).all();
Gives:
[
{
"key":"4 INCH CAST FIBREGLASS",
"value":{
"qty":{"sum":126},
"price":{"sum":270648},
"category": {"valueList":["MEDICAL DISPOSABLE"]}
}
},
{
"key":"ABF CREAM 20G",
"value":{
"qty":{"sum":150},
"price":{"sum":150169.29},
"category": {"valueList":["DERMATOLOGICALS"]}
}
},
{
"key":"NP Slow Meedrol Methylprednisolone Sodium Succinate Injection USP 500mg x 1 Vial",
"value":{
"qty":{"sum":100},
"price":{"sum":44576},
"category": {"valueList":["CORTICOSTERIODS"]}
}
}
]
Thank you.
Given a data that looks like:
I would like to add the category of the keys to the values when grouped by names alongside the sum of prices and qtys for further processing. With the help of
crossfilter
andreductio
, I got what is consumable by other functions, just that I couldn't figure out how to add the category of each of the keys to it.What I am currently using:
Current Result:
Desired Result:
Thank you.