mardi 15 avril 2014

Group by on more than 2 column on JSON array using Underscore JS


Vote count:

0




I am referring following code for group by on 2 columns and performing aggregation on cost and impression on JSON array using Undescore JS


Group by and aggregation on JSON array using Underscore JSenter image description hereoup-by-and-aggregation-on-json-array-using-underscore-js/22954510?noredirect=1#22954510



var result = _.chain(data)
.groupBy("FlexCategoryName")
.map(function(value, key) {
return _.chain(value)
.groupBy("VENUE_ID")
.map(function(value1, venue_id) {
return {
FlexCategoryName: key,
Cost: sum(_.pluck(value1, "Cost")),
Impressions: sum(_.pluck(value1, "Impressions")),
VENUE_ID: venue_id
}
})
.value();
})
.value();


i need to generalize above code that i can perform group by more than n number of columns. I have attached one image in which i am performing group by on Flex Category ID and Venue_ID using above code . I also want to group data based on to date column .i can do writing a nested code in above scrip but i need to a make it generic where i can pass n number of columns for group by and then perform aggregation .


enter image description here



asked 1 min ago






Aucun commentaire:

Enregistrer un commentaire