Hi all,
In one of my buckets I have records that have the following fields (among other fields):
accountnumber,
advisorcode,
year,
month,
day,
value_month,
value_quarter,
value_year
So per accountnumber per date, I have stored some values. Also I have stored which advisor was assigned to that accountnumber on that date. One advisor can have multiple accountnumbers assigned on the same date.
I want to create a view with summaries per advisor per date, with summaries of the values. So I am looking for:
advisorcode,
year,
month,
day,
total_value_month_on_that_date,
total_value_quarter_on_that_date,
total_value_year_on_that_date
So far I have tried to create a view, with the following map:
function (doc, meta)
{
emit([doc.advisorcode, doc.year, doc.month, doc.day], [doc.value_month, doc.value_quarter, doc.value_year]);
}
and various reduces, among which:
function(key, values, rereduce)
{
var result = {total_value_month:0, total_value_quarter:0, total_value_year:0};
for(v in values)
{
result.total_value_month += values[v].value_month;
result.total_value_quarter += values[v].value_quarter;
result.total_value_year += values[v].value_year;
}
return result;
}
I also created versions with a rereduce section, but nothing works. I must be doing something wrong. Does anybody have a hint or a solution direction for me? Thanx in advance!