I am currently grouping my data by account but also need to group it by salesperson too. However, I cannot figure out how to successfully implement the functionality so that it is grouping by multiple fields at the same time. Could someone offer up some guidance as to how I can do that?
Here is my function that groups my data as of right now:
filteredData[rep.id] = _.chain(filteredData[rep.id]).groupBy('account').map(function(v, i) {
return {
customer: i,
salesperson: _.reduce(v, function(res, val) {
return val['salesperson'];
},0),
sales_ytd: _.reduce(v, function(res, val) {
return res + Number(val['sales - ytd']);
},0),
mgn$_ytd: _.reduce(v, function(res, val) {
return res + Number(val['margin - ytd']);
},0),
sales_last: _.reduce(v, function(res, val) {
return res + Number(val['sales - pytd']);
},0),
mgn$_last: _.reduce(v, function(res, val) {
return res + Number(val['margin - pytd']);
},0)
}
}).value();