weather data is incorrect?

When min date is 2009.01.01 , how come the result below has a 2008.12.27?

Hi @vjay.b5

When q groups dates using 7 xbar date, it divides the data into 7-day buckets, each bucket labelled by the start of that 7-day period.

Because the data begins on 2009.01.01, but the natural 7-day alignment for q falls on 2009.01.03, q aligns the buckets to that boundary. As a result, the first two dates—2009.01.01 and 2009.01.02—do not fill a complete 7-day group by themselves. q still includes them, but it assigns them to the bucket whose label is 2008.12.27, which is simply the start date of the 7-day period that includes 2009.01.01.

This label does not mean data came from 2008.12.27; it’s only the calculated start of that 7-day interval.

I hope this clears things up and if you have any questions about this, let me know! :slight_smile:

Thanks Megan, that’s very helpful. But what do you mean by “the natural 7-day alignment for q falls on 2009.01.03“ ? 2009.01.03 is Saturday (not Sunday) just curious how q determine the bucket period here automatically. (Am new to q/kdb perhaps am missing something)

@vjay.b5 a xbar b returns the largest multiple of a that is ≤ b.

So for example, say we have 7 xbar 2009.01.01 it will convert the date to internal integers from 2000.01.01 (the epoch).

2009.01.01 = 3288 days

To find the nearest multiple of 7 to 3288:

3288 ÷ 7 = 469.714…

The closest two multiples to 7 are:

  1. Lower multiple:
    469 × 7 = 3283 (2008.12.27)
  2. Upper multiple:
    470 × 7 = 3290 (2009.01.03)

7 xbar date groups dates into 7-day buckets aligned to multiples of 7 days since 2000.01.01, producing week-based buckets like:

2008.12.27
2009.01.03
2009.01.10

I hope this helps!