function accumulate_group(source_group) { return { all:function () { var cumulate = 0; return source_group.all().map(function(d) { cumulate += d.value; return {key:d.key, value:cumulate}; }); } }; }
On Jun 4, 2020, at 11:58 AM, Stu <stutr...@gmail.com> wrote:
Hi all,This fiddle shows a table with basic reduction by date.I have added a column (qtyPaul) that correctly shows values against the names that match "paul".Is is possible to calculate all these values where the date is <= itself as in the table below:Effectively a running total with criteria
<table2.PNG>
Thanks, Stu
--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/7104303a-3eef-447f-bbae-d046f3680788%40googlegroups.com.
<table2.PNG>
var stuffBy_date = dateRef.group().reduce( function(p, v) { ++p.count; p.qty += +v.qty; return p; }, function(p, v) { --p.count; p.qty -= +v.qty; return p; }, function() { return { count: 0, name: 0, qty: 0, qtyPaul: 0, qtyToDate: 0 }; });
function accumulate_group_field(source_group, field, accfield) {
return { all:function () { var cumulate = 0; return source_group.all().map(function(d) {
cumulate += d.value[field]; return {key:d.key, value: {...d.value, [accfield]: cumulate}}; }); } }; }
var accStuffByDate = accumulate_group_field(stuffByDate, 'qtyPaul', 'paulToDate');
On Jun 5, 2020, at 5:16 AM, Stu <stutr...@gmail.com> wrote:
--
You received this message because you are subscribed to the Google Groups "dc-js user group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-user-gro...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/dc-js-user-group/78a962a7-e942-4f05-bab3-bf6095732c32o%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to dc-js-us...@googlegroups.com.