Reduce map view sometimes return only null values


I have created a view that summarizes some data per entity per day, when that day is the end of the month. I will give you a simplified overview of the data. In short, the bucket contains records that look like this:


My view index code is like this (there are more values, but for the example this is enough I hope):

function (doc, meta)
if (doc.is_end_of_month== true)
emit([doc.person_code, doc.year, doc.month,], [doc.some_value]);

My reduce part looks like this:

function(key, values, rereduce)
var result = { sum_of_some_value = 0;
for(v in values)
var row = values[v];
if (row[0] != null)
result.sum_of_some_value += row[0];
return result;

After publishing it to production and retrieving data (in production, not design), using startkey, endkey and grouping=4, I do get a result for each end of month record, but for some/most retrieved result records I will get a 0 (zero) value. When I leave out the null check, I will even get null instead of 0 (zero). I am absolutely sure that there are records that should be summarized. I’ve tried recreating and rebuilding a number of times. I am out of clues, maybe one of you has a hint for me. Thanx!