Home / Tableau Tutorial / Day 6
Day 6 — Working with dates
Truncating, parting and comparing dates - and the difference that trips people up.
DATEPART gives you a number, DATENAME gives you text
Every calculation on this page runs against the Orders data source below - 48 rows, dimensions in blue, measures in green, exactly as Tableau colours them.
DATENAME returns text, and text sorts alphabetically
Put DATENAME("month", ...) on an axis and your months run April, August, December, February. Use DATEPART for anything you need in the right order, and DATENAME only for labels.
DATETRUNC - the one that matters most
DATETRUNC rounds a date down to the start of a period, and keeps it a date. That is how you group by month without losing chronological order.
DATEPART vs DATETRUNC in one line
Use DATEPART for seasonality across years. Use DATETRUNC for a trend line over time.
DATEPART("month", ...) gives 3 for every March - March 2024 and March 2025 land together.
DATETRUNC("month", ...) gives 1 March 2024 and 1 March 2025 separately.
Use DATEPART for seasonality across years. Use DATETRUNC for a trend line over time.
Seeing the difference
That view has one row per order date - too much detail to read. In Tableau you would drop DATETRUNC by month on Rows instead, giving one row per month.
Splitting by year
The two years add up to the total, and 2025 grew by 465,600 on 2024.
DATEDIFF and DATEADD
DATEDIFF counts boundaries crossed, not elapsed time. From 31 December to 1 January is one year by DATEDIFF, even though it is one day.
Quarterly reporting
Indian financial years
The financial year runs April to March, so FY 2025-26 starts in April 2025. A common approach is a calculated field:
IF DATEPART("month",[Order Date]) >= 4 THEN DATEPART("year",[Order Date]) ELSE DATEPART("year",[Order Date]) - 1 END - the calendar year the financial year began in.Try these yourself
- Show the start of the quarter for each of the first six orders.
- Total the sales for March 2025.
- Work out how many months the data covers.
- Explain when you would use DATEPART instead of DATETRUNC.
- Build a financial-year label reading "FY 2025-26".
