Tableau function Date

Tableau MAKEDATE to SQL

MAKEDATE(year, month, day) returns a date: MAKEDATE(2025, 1, 31) is 31 January 2025. Out-of-range values are adjusted into a date, so 29 February 2025 becomes 1 March 2025 and day 0 is the last day of the previous month. DuckDB's make_date rejects those values, so the matching SQL adds months and days to 1 January.

Updated · Checked on the xmetric engine

What is the syntax?

MAKEDATE(year, month, day)
year, month, day
integers.

Returns a date. Out-of-range months and days roll over into the next or previous month. Null if any part 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.

What date do the year, month and day columns make?

Tableau

MAKEDATE([Y], [M], [D])

SQL (DuckDB)

SELECT
  CAST (make_date(Y, 1, 1) + to_months(M - 1) + to_days(D - 1) AS DATE) AS result
FROM input
ORDER BY id

Row 7 is 29 February 2025, which doesn't exist; Tableau rolls it into 1 March. Starting from 1 January and adding months, then days, rolls over the same way.

YMDResult
2,021112021-01-01
2,021132021-01-03
2,0242292024-02-29
2,02412292024-12-29
2,02412302024-12-30
2,0251312025-01-31
2,0252292025-03-01
2,025322025-03-02
null

The Tableau formula and the SQL return the same 9 rows.

What is the last day of each row's month?

Tableau

MAKEDATE([Y], [M] + 1, 0)

SQL (DuckDB)

SELECT last_day(make_date(Y, M, 1)) AS result
FROM input
ORDER BY id

Day 0 of next month is the last day of this one, a common Tableau idiom. In DuckDB, last_day() says it directly: 29 February in 2024, 28 February in 2025.

YMResult
2,02112021-01-31
2,02112021-01-31
2,02422024-02-29
2,024122024-12-31
2,024122024-12-31
2,02512025-01-31
2,02522025-02-28
2,02532025-03-31
null

The Tableau formula and the SQL return the same 9 rows.

Where does a straight translation go wrong?

Common mistake

Why does make_date lose the invalid row?

DuckDB's make_date(2025, 2, 29) is an error, so the bare call fails the query and try() turns the row into null. Tableau adjusts it to 1 March 2025.

Tableau

MAKEDATE([Y], [M], [D])

Tempting SQL

SELECT try(make_date(Y, M, D)) AS result
FROM input
ORDER BY id

SQL that matches

SELECT
  CAST (make_date(Y, 1, 1) + to_months(M - 1) + to_days(D - 1) AS DATE) AS result
FROM input
ORDER BY id
YMDTableauTempting SQLSQL that matches
2,021112021-01-012021-01-012021-01-01
2,021132021-01-032021-01-032021-01-03
2,0242292024-02-292024-02-292024-02-29
2,02412292024-12-292024-12-292024-12-29
2,02412302024-12-302024-12-302024-12-30
2,0251312025-01-312025-01-312025-01-31
2,0252292025-03-01null2025-03-01
2,025322025-03-022025-03-022025-03-02
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 DATE_FROM_PARTS(Y, M, D) AS result
FROM input
ORDER BY id

Snowflake documentation

BigQuery

SELECT
  DATE_ADD(DATE_ADD(DATE(Y, 1, 1), INTERVAL M - 1 MONTH), INTERVAL D - 1 DAY) AS result
FROM input
ORDER BY id

BigQuery documentation

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

What does MAKEDATE do with 29 February in a non-leap year?

It rolls over to 1 March. Tableau's help: incorrectly entered values are adjusted into a date. Row 7 of the sample shows it.

Does MAKEDATE work on every connection?

Tableau's help lists it as available for Tableau data extracts; on a live connection, check that the database supports it.

What if one of the parts is null?

The result is null, as on the blank last row.

Where is this documented?