Summing and grouping in a view (with reduce?)

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!

For your info: I found a solution. Example:

MAP:
function(doc, meta)
{
emit([doc.code, doc.year, doc.month, doc.date], [doc.value1, doc.value2]);
}

REDUCE:
function(key, values, rereduce)
{
var result = {tot_value1:0, tot_value2:0};
for(v in values)
{
result.tot_value1 += result.tot_value1 + values[v][0];
result.tot_value2 += result.tot_value1 + values[v][1];
}

return result;
}

This gives me the option to select on different levels for a code, simply by setting the groupby depth. Maybe not the most beautifull, but it works ok.