Tableau function Date

Tableau ISOWEEK to SQL

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)

SELECT week(Ordered) AS result
FROM input
ORDER BY id

Order 5 on Monday 30 December 2024 is already week 1 of 2025; order 4, the day before, is week 52.

OrderedResult
2021-01-01 08:0053
2021-01-03 18:4553
2024-02-29 10:159
2024-12-29 16:25:4052
2024-12-30 09:051
2025-01-31 23:59:595
2025-03-01 00:009
2025-03-02 12:30:159
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)

SELECT isoyear(Ordered) * 100 + week(Ordered) AS result
FROM input
ORDER BY id

Pair the ISO week with the ISO year so the key sorts in time order.

OrderedResult
2021-01-01 08:00202,053
2021-01-03 18:45202,053
2024-02-29 10:15202,409
2024-12-29 16:25:40202,452
2024-12-30 09:05202,501
2025-01-31 23:59:59202,505
2025-03-01 00:00202,509
2025-03-02 12:30:15202,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

SELECT year(Ordered) * 100 + week(Ordered) AS result
FROM input
ORDER BY id

SQL that matches

SELECT isoyear(Ordered) * 100 + week(Ordered) AS result
FROM input
ORDER BY id
OrderedTableauTempting SQLSQL that matches
2021-01-01 08:00202,053202,153202,053
2021-01-03 18:45202,053202,153202,053
2024-02-29 10:15202,409202,409202,409
2024-12-29 16:25:40202,452202,452202,452
2024-12-30 09:05202,501202,401202,501
2025-01-31 23:59:59202,505202,505202,505
2025-03-01 00:00202,509202,509202,509
2025-03-02 12:30:15202,509202,509202,509
nullnullnull

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

SELECT strftime(Ordered, '%W') AS result
FROM input
ORDER BY id

SQL that matches

SELECT week(Ordered) AS result
FROM input
ORDER BY id
OrderedTableauTempting SQLSQL that matches
2021-01-01 08:00530053
2021-01-03 18:45530053
2024-02-29 10:159099
2024-12-29 16:25:40525252
2024-12-30 09:051531
2025-01-31 23:59:595045
2025-03-01 00:009089
2025-03-02 12:30:159089
nullnullnull

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

SELECT WEEKISO(Ordered) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT EXTRACT(ISOWEEK FROM Ordered) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own ISOWEEK formula return?

Edit the formula and run it on the 9 sample rows. Fields: [id], [Ordered], [Due], [Text], [Local], [Y], [M], [D].

Runs in your browser on the xmetric engine. Nothing is uploaded.

Which functions go with it?

What do people ask about ISOWEEK?

Can ISOWEEK be 53?

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.

Where is this documented?