3

Is it possible to define the start and end day of a 'week' in the Keen IO query language? I have a query like:

var query = new Keen.Query("count", {
    eventCollection: "add_to_carts",
    timeframe: "previous_2_weeks",
    interval: "weekly"
});

The default result of my query shows the week starting Sunday and running to Saturday, but I need my data to start on Saturday - is that possible?

What we want to do is find data for the current week and the previous week in one query (using intervals) and separate the two week's results for comparison - with each week running from Saturday to Friday.

tbarn
  • 348
  • 1
  • 9
Michelle Wetzler
  • 734
  • 4
  • 16

1 Answers1

3

It would be possible with absolute timeframes and a custom interval definition, like this:

var query = new Keen.Query("count", {
    eventCollection: "add_to_carts",
    timeframe: {
        start: "2016-08-01",
        end: "2016-09-12"
    },
    timezone: "US/Pacific",
    interval: "every_7_days"
}); 

Instead of using "weekly", it uses a custom interval definition of "every_7_days". This would effectively be one query starting on a Saturday some time in the past, and you would get as many interval results as 7 day blocks from that Saturday - essentially creating previous week and this week in the response.

Here's a fiddle that shows this query and resulting chart.

enter image description here

Michelle Wetzler
  • 734
  • 4
  • 16