ISOWEEKDAY(date) returns the ISO 8601 day of the week: Monday is 1 and Sunday is 7, whatever the data source's week start. DuckDB's isodow() is the same. dayofweek() is not: it counts from Sunday = 0.
Updated · Checked on the xmetric engine
What is the syntax?
ISOWEEKDAY(date)
date
a date or date-time.
Returns an integer from 1 (Monday) to 7 (Sunday). 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 weekday was each order placed on?
Tableau
ISOWEEKDAY([Ordered])
SQL (DuckDB)
SELECTisodow(Ordered) AS result
FROM input
ORDERBY id
Order 5 is a Monday (1); orders 2, 4 and 8 are Sundays (7).
Ordered
Result
2021-01-0108:00
5
2021-01-0318:45
7
2024-02-2910:15
4
2024-12-2916:25:40
7
2024-12-3009:05
1
2025-01-3123:59:59
5
2025-03-0100:00
6
2025-03-0212:30:15
7
null
✓ The Tableau formula and the SQL return the same 9 rows.
Was the order placed at the weekend?
Tableau
ISOWEEKDAY([Ordered]) >=6
SQL (DuckDB)
SELECTisodow(Ordered) >=6AS result
FROM input
ORDERBY id
With Monday = 1, Saturday and Sunday are the two highest numbers.
Ordered
Result
2021-01-0108:00
false
2021-01-0318:45
true
2024-02-2910:15
false
2024-12-2916:25:40
true
2024-12-3009:05
false
2025-01-3123:59:59
false
2025-03-0100:00
true
2025-03-0212:30:15
true
null
✓ The Tableau formula and the SQL return the same 9 rows.
Where does a straight translation go wrong?
Common mistake
Why does dayofweek() give 0 for Sunday?
DuckDB's dayofweek() counts from Sunday = 0 to Saturday = 6. ISOWEEKDAY counts Monday = 1 to Sunday = 7, so every Sunday is 0 instead of 7 and every other day matches only by accident.
Tableau
ISOWEEKDAY([Ordered])
Tempting SQL
SELECTdayofweek(Ordered) AS result
FROM input
ORDERBY id
SQL that matches
SELECTisodow(Ordered) AS result
FROM input
ORDERBY id
Ordered
Tableau
Tempting SQL
SQL that matches
2021-01-0108:00
5
5
5
2021-01-0318:45
7
0
7
2024-02-2910:15
4
4
4
2024-12-2916:25:40
7
0
7
2024-12-3009:05
1
1
1
2025-01-3123:59:59
5
5
5
2025-03-0100:00
6
6
6
2025-03-0212:30:15
7
0
7
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
SELECTDAYOFWEEKISO(Ordered) AS result
FROM input
ORDERBY id