Week granularity dates are incorrect with MS SQL
- Dominant language
- Rust
- Stars
- 20.8k
- Forks
- 2.1k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 181
Description
**Describe the bug**
When you query a cube with a time dimension and specify the `week` granularity, the dates and data for each date are incorrect. They seem to be off by 1.
**To Reproduce**
1. Set up an MS SQL table with a date column
2. Insert 1 row per date from 2023-12-30 to 2024-01-10:
1 2023-12-30 00:00:00.0000000
2 2023-12-31 00:00:00.0000000
3 2024-01-01 00:00:00.0000000
4 2024-01-02 00:00:00.0000000
5 2024-01-03 00:00:00.0000000
6 2024-01-04 00:00:00.0000000
7 2024-01-05 00:00:00.0000000
8 2024-01-06 00:00:00.0000000
9 2024-01-07 00:00:00.0000000
10 2024-01-08 00:00:00.0000000
11 2024-01-09 00:00:00.0000000
12 2024-01-10 00:00:00.0000000
3. Set up a cube that uses this table with a time dimension and a count measure.
4. Query the cube with week granularity and observe results
**Expected behavior**
Results should show:
- Week starting Sunday 24th December 2023 has 1 value
- Week starting Sunday 31st December 2023 has 7 values
- Week starting Sunday 7th January 2024 has 4 values
But unfortunately results show:
- Week starting Monday 25th December 2023 has 1 value
- Week starting Monday 1st January 2024 has 7 values
- Week starting Monday 8th January 2024 has 4 values
Suppling a filter for the date range compounds the issue.
**Version:**
[0.34.54]
**Additional context**
Seems to be an issue with how the week is calculated with this SQL fragment:
```
dateadd(
week,
DATEDIFF(
week,
0,
TODATETIMEOFFSET(
"date",
'+00:00'
)
),
0
)
```
I am unsure what the fix would be though.
Contributor guide
Assessment
This issue has not been assessed yet.