In pseudo-sql terms, you are trying to do the following:
SELECT COUNT(book) GROUP BY author, month
The way I approach this problem is to combine the fields into a single dimension. Therefore, in your case, I would combine the information of the month and the author together into a dimension.
Let this be our test data:
var cf = crossfilter([ { date:"1 jan 2014", author: "Mr X", book: "Book 1" }, { date:"2 jan 2014", author: "Mr X", book: "Book 2" }, { date:"3 feb 2014", author: "Mr X", book: "Book 3" }, { date:"1 mar 2014", author: "Mr X", book: "Book 4" }, { date:"2 apr 2014", author: "Mr X", book: "Book 5" }, { date:"3 apr 2014", author: "Mr X", book: "Book 6"}, { date:"1 jan 2014", author: "Ms Y", book: "Book 7" }, { date:"2 jan 2014", author: "Ms Y", book: "Book 8" }, { date:"3 jan 2014", author: "Ms Y", book: "Book 9" }, { date:"1 mar 2014", author: "Ms Y", book: "Book 10" }, { date:"2 mar 2014", author: "Ms Y", book: "Book 11" }, { date:"3 mar 2014", author: "Ms Y", book: "Book 12" }, { date:"4 apr 2014", author: "Ms Y", book: "Book 13" } ]);
Size is determined as follows:
var dimensionMonthAuthor = cf.dimension(function (d) { var thisDate = new Date(d.date); return 'month='+thisDate.getMonth()+';author='+d.author; });
And now we can just simply make an abbreviation counter to calculate how many books there are per author, per month (i.e. per unit):
var monthAuthorCount = dimensionMonthAuthor.group().reduceCount(function (d) { return d.book; }).all();
And the results are as follows:
{"key":"month=0;author=Mr X","value":2} {"key":"month=0;author=Ms Y","value":3} {"key":"month=1;author=Mr X","value":1} {"key":"month=2;author=Mr X","value":1} {"key":"month=2;author=Ms Y","value":3} {"key":"month=3;author=Mr X","value":2} {"key":"month=3;author=Ms Y","value":1}