XD-906: Add query by month to aggregate counter.

Also changed the test to run across more date boundaries
(e.g. 2013-2014) and fixed some bugs related to this.