Tableau function Date

Tableau ISOQUARTER to SQL

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)

SELECT
  CASE
    WHEN week(Ordered) = 53 THEN 4
    ELSE CAST (floor((week(Ordered) - 1) / 13) + 1 AS INTEGER)
    END AS result
FROM input
ORDER BY 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.

OrderedResult
2021-01-01 08:004
2021-01-03 18:454
2024-02-29 10:151
2024-12-29 16:25:404
2024-12-30 09:051
2025-01-31 23:59:591
2025-03-01 00:001
2025-03-02 12:30:151
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)

SELECT
  isoyear(Ordered)
    * 10
    + CASE
    WHEN week(Ordered) = 53 THEN 4
    ELSE CAST (floor((week(Ordered) - 1) / 13) + 1 AS INTEGER)
    END AS result
FROM input
ORDER BY id

20204 reads as 2020 Q4: the label for the first days of January 2021.

OrderedResult
2021-01-01 08:0020,204
2021-01-03 18:4520,204
2024-02-29 10:1520,241
2024-12-29 16:25:4020,244
2024-12-30 09:0520,251
2025-01-31 23:59:5920,251
2025-03-01 00:0020,251
2025-03-02 12:30:1520,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

SELECT
  CAST (least(4, floor((week(Ordered) - 1) / 13) + 1) AS INTEGER) AS result
FROM input
ORDER BY id

SQL that matches

SELECT
  CASE
    WHEN week(Ordered) = 53 THEN 4
    ELSE CAST (floor((week(Ordered) - 1) / 13) + 1 AS INTEGER)
    END AS result
FROM input
ORDER BY id
OrderedTableauTempting SQLSQL that matches
2021-01-01 08:00444
2021-01-03 18:45444
2024-02-29 10:15111
2024-12-29 16:25:40444
2024-12-30 09:05111
2025-01-31 23:59:59111
2025-03-01 00:00111
2025-03-02 12:30:15111
null4null

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

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

SQL that matches

SELECT
  CASE
    WHEN week(Ordered) = 53 THEN 4
    ELSE CAST (floor((week(Ordered) - 1) / 13) + 1 AS INTEGER)
    END AS result
FROM input
ORDER BY id
OrderedTableauTempting SQLSQL that matches
2021-01-01 08:00414
2021-01-03 18:45414
2024-02-29 10:15111
2024-12-29 16:25:40444
2024-12-30 09:05141
2025-01-31 23:59:59111
2025-03-01 00:00111
2025-03-02 12:30:15111
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
  IFF(WEEKISO(Ordered) = 53, 4, FLOOR((WEEKISO(Ordered) - 1) / 13) + 1) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT
  IF(EXTRACT(ISOWEEK FROM Ordered) = 53, 4, DIV(EXTRACT(ISOWEEK FROM Ordered) - 1, 13) + 1) AS result
FROM input
ORDER BY id

BigQuery documentation

What does your own ISOQUARTER 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 ISOQUARTER?

How is ISOQUARTER different from QUARTER?

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.

Where is this documented?