ISOQUARTER(date) returns the quarter of the ISO 8601 week-based year: ISO weeks 1-13 are quarter 1, 14-26 quarter 2, 27-39 quarter 3 and 40-53 quarter 4. DuckDB has no ISO quarter function, so compute it from week(), the ISO week. 1 January 2021 is ISO week 53 of 2020, so it is quarter 4.
Updated · Checked on the xmetric engine
What is the syntax?
ISOQUARTER(date)
date
a date or date-time.
Returns an integer from 1 to 4: the quarter of the ISO week-based year. 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 quarter was each order placed in?
Tableau
ISOQUARTER([Ordered])
SQL (DuckDB)
SELECTCASEWHENweek(Ordered) =53THEN4ELSECAST (floor((week(Ordered) -1) /13) +1AS INTEGER)
ENDAS result
FROM input
ORDERBY id
Week 53 goes to quarter 4; every other week is (week - 1) / 13, rounded down, plus 1. Orders 1, 2 and 4 are quarter 4; order 5 is quarter 1.
Ordered
Result
2021-01-0108:00
4
2021-01-0318:45
4
2024-02-2910:15
1
2024-12-2916:25:40
4
2024-12-3009:05
1
2025-01-3123:59:59
1
2025-03-0100:00
1
2025-03-0212:30:15
1
null
✓ The Tableau formula and the SQL return the same 9 rows.
How do I label each order with its ISO year and quarter?
Tableau
ISOYEAR([Ordered]) *10+ISOQUARTER([Ordered])
SQL (DuckDB)
SELECTisoyear(Ordered)
*10+CASEWHENweek(Ordered) =53THEN4ELSECAST (floor((week(Ordered) -1) /13) +1AS INTEGER)
ENDAS result
FROM input
ORDERBY id
20204 reads as 2020 Q4: the label for the first days of January 2021.
Ordered
Result
2021-01-0108:00
20,204
2021-01-0318:45
20,204
2024-02-2910:15
20,241
2024-12-2916:25:40
20,244
2024-12-3009:05
20,251
2025-01-3123:59:59
20,251
2025-03-0100:00
20,251
2025-03-0212:30:15
20,251
null
✓ The Tableau formula and the SQL return the same 9 rows.
Where does a straight translation go wrong?
Common mistake
Why does least(4, ...) give quarter 4 for a missing date?
DuckDB's least() skips nulls, so least(4, NULL) is 4. Capping week 53 with least() turns the blank row into quarter 4; Tableau returns null. Use a CASE that leaves nulls alone.
Tableau
ISOQUARTER([Ordered])
Tempting SQL
SELECTCAST (least(4, floor((week(Ordered) -1) /13) +1) AS INTEGER) AS result
FROM input
ORDERBY id
SQL that matches
SELECTCASEWHENweek(Ordered) =53THEN4ELSECAST (floor((week(Ordered) -1) /13) +1AS INTEGER)
ENDAS result
FROM input
ORDERBY id
Ordered
Tableau
Tempting SQL
SQL that matches
2021-01-0108:00
4
4
4
2021-01-0318:45
4
4
4
2024-02-2910:15
1
1
1
2024-12-2916:25:40
4
4
4
2024-12-3009:05
1
1
1
2025-01-3123:59:59
1
1
1
2025-03-0100:00
1
1
1
2025-03-0212:30:15
1
1
1
null
4
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 quarter() give 1 for 1 January 2021?
quarter() is the calendar quarter. ISOQUARTER follows the ISO week, and 1 January 2021 is in ISO week 53 of 2020: quarter 4.
Tableau
ISOQUARTER([Ordered])
Tempting SQL
SELECTquarter(Ordered) AS result
FROM input
ORDERBY id
SQL that matches
SELECTCASEWHENweek(Ordered) =53THEN4ELSECAST (floor((week(Ordered) -1) /13) +1AS INTEGER)
ENDAS result
FROM input
ORDERBY id
Ordered
Tableau
Tempting SQL
SQL that matches
2021-01-0108:00
4
1
4
2021-01-0318:45
4
1
4
2024-02-2910:15
1
1
1
2024-12-2916:25:40
4
4
4
2024-12-3009:05
1
4
1
2025-01-3123:59:59
1
1
1
2025-03-0100:00
1
1
1
2025-03-0212:30:15
1
1
1
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
SELECTIFF(WEEKISO(Ordered) =53, 4, FLOOR((WEEKISO(Ordered) -1) /13) +1) AS result
FROM input
ORDERBY id
QUARTER uses calendar months. ISOQUARTER uses ISO weeks, so a few days around New Year land in the other year's quarter: 30 December 2024 is ISO quarter 1 (of 2025).
Which quarter holds ISO week 53?
Quarter 4, which then has 14 weeks.
How do I label an ISO quarter with its year?
Pair it with ISOYEAR, not YEAR: STR(ISOYEAR([Ordered])) + " Q" + STR(ISOQUARTER([Ordered])) gives 2020 Q4 for 1 January 2021.