ISOWEEK(date) returns the ISO 8601 week number: weeks start on Monday, and week 1 is the week that holds the year's first Thursday. DuckDB's week() (and weekofyear()) is the same ISO week. The trap is pairing it with the calendar year: 1 January 2021 is ISO week 53 of 2020, so a year-week key needs isoyear().
Updated · Checked on the xmetric engine
What is the syntax?
ISOWEEK(date)
date
a date or date-time.
Returns an integer from 1 to 53: the ISO 8601 week. Null if the date is null.
What does it return, and what is the SQL?
Each example runs on the same 9 sample rows twice: the Tableau formula on the xmetric engine, and the SQL in DuckDB.
Which ISO week was each order placed in?
Tableau
ISOWEEK([Ordered])
SQL (DuckDB)
SELECTweek(Ordered) AS result
FROM input
ORDERBY id
Order 5 on Monday 30 December 2024 is already week 1 of 2025; order 4, the day before, is week 52.
Ordered
Result
2021-01-0108:00
53
2021-01-0318:45
53
2024-02-2910:15
9
2024-12-2916:25:40
52
2024-12-3009:05
1
2025-01-3123:59:59
5
2025-03-0100:00
9
2025-03-0212:30:15
9
null
✓ The Tableau formula and the SQL return the same 9 rows.
How do I build a year-week key such as 202053?
Tableau
ISOYEAR([Ordered]) *100+ISOWEEK([Ordered])
SQL (DuckDB)
SELECTisoyear(Ordered) *100+week(Ordered) AS result
FROM input
ORDERBY id
Pair the ISO week with the ISO year so the key sorts in time order.
Ordered
Result
2021-01-0108:00
202,053
2021-01-0318:45
202,053
2024-02-2910:15
202,409
2024-12-2916:25:40
202,452
2024-12-3009:05
202,501
2025-01-3123:59:59
202,505
2025-03-0100:00
202,509
2025-03-0212:30:15
202,509
null
✓ The Tableau formula and the SQL return the same 9 rows.
Where does a straight translation go wrong?
Common mistake
Why does year() * 100 + week() put 1 January 2021 after the end of 2021?
The week belongs to ISO year 2020, but year() says 2021, so the key is 202153, a week that doesn't exist. 30 December 2024 becomes 202401. Use isoyear() with the ISO week.
Tableau
ISOYEAR([Ordered]) *100+ISOWEEK([Ordered])
Tempting SQL
SELECTyear(Ordered) *100+week(Ordered) AS result
FROM input
ORDERBY id
SQL that matches
SELECTisoyear(Ordered) *100+week(Ordered) AS result
FROM input
ORDERBY id
Ordered
Tableau
Tempting SQL
SQL that matches
2021-01-0108:00
202,053
202,153
202,053
2021-01-0318:45
202,053
202,153
202,053
2024-02-2910:15
202,409
202,409
202,409
2024-12-2916:25:40
202,452
202,452
202,452
2024-12-3009:05
202,501
202,401
202,501
2025-01-3123:59:59
202,505
202,505
202,505
2025-03-0100:00
202,509
202,509
202,509
2025-03-0212:30:15
202,509
202,509
202,509
null
null
null
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
Common mistake
Why does strftime('%W') not match ISOWEEK?
%W starts weeks on Monday but counts the days before the first Monday as week 00, so 1 January 2021 is '00', not 53. %V or week() is the ISO week.
Tableau
ISOWEEK([Ordered])
Tempting SQL
SELECTstrftime(Ordered, '%W') AS result
FROM input
ORDERBY id
SQL that matches
SELECTweek(Ordered) AS result
FROM input
ORDERBY id
Ordered
Tableau
Tempting SQL
SQL that matches
2021-01-0108:00
53
00
53
2021-01-0318:45
53
00
53
2024-02-2910:15
9
09
9
2024-12-2916:25:40
52
52
52
2024-12-3009:05
1
53
1
2025-01-3123:59:59
5
04
5
2025-03-0100:00
9
08
9
2025-03-0212:30:15
9
08
9
null
null
null
✓ The SQL that matches returns the Tableau result on every row; the marked cells are where the tempting SQL differs.
How do I write it in Snowflake or BigQuery?
The first example, written for each warehouse from its documentation. These are not run here; DuckDB is.
Snowflake
SELECTWEEKISO(Ordered) AS result
FROM input
ORDERBY id
Yes, in years with 53 ISO weeks, such as 2020: 1 and 3 January 2021 are both in ISO week 53 of 2020. Tableau's help lists 1-52, but the ISO standard allows 53.
Does the data source's week start change ISOWEEK?
No. ISO weeks always start on Monday, whatever the data source's first day of week is.
How is ISOWEEK different from WEEK?
WEEK starts week 1 on 1 January and uses the data source's week start (Sunday in US English). On 29 December 2024 WEEK is 53 and ISOWEEK is 52.