0
0
Tableaubi_tool~5 mins

Date calculations (DATEDIFF, DATEADD) in Tableau - Step-by-Step Guide

Choose your learning style9 modes available
Introduction
Date calculations help you find differences between dates or add time to dates. This is useful when you want to see how much time passed or predict future dates in your data.
When you want to find how many days passed between order date and delivery date.
When you need to add 7 days to a start date to find a deadline.
When you want to compare sales month over month by adding or subtracting months.
When you want to calculate the number of years between a customer's signup date and today.
When you want to shift dates in your data to analyze trends over different time periods.
Steps
Step 1: Click
- Analysis menu
A dropdown menu appears with calculation options
Step 2: Select
- Create Calculated Field
A dialog box opens to enter a new calculation
Step 3: Type
- Calculation editor
You can write your date calculation formula
💡 Use DATEDIFF to find difference between two dates, e.g. DATEDIFF('day', [Start Date], [End Date])
Step 4: Type
- Calculation editor
You can write your date addition formula
💡 Use DATEADD to add time to a date, e.g. DATEADD('month', 1, [Order Date])
Step 5: Click
- OK button in the calculation editor
The new calculated field appears in the Data pane
Step 6: Drag
- New calculated field to Rows or Columns shelf
The visualization updates showing the date calculation results
Before vs After
Before
Data shows order dates and delivery dates as separate columns without any calculation
After
A new column shows the number of days between order and delivery for each record
Settings Reference
Date Part
📍 Inside DATEDIFF and DATEADD functions in calculation editor
Defines the unit of time to calculate difference or add (e.g., days, months)
Default: day
Start Date
📍 First date argument in DATEDIFF or DATEADD
The date to start calculation from
Default: None
End Date / Number
📍 Second date argument in DATEDIFF or number to add in DATEADD
The date to compare to or number of units to add
Default: None
Common Mistakes
Using DATEDIFF with wrong date part like 'days' instead of 'day'
Tableau requires exact date part keywords like 'day', not plural
Use correct date part keywords such as 'day', 'month', 'year' exactly as Tableau expects
Using DATEADD with a negative number but forgetting to put minus sign
Without minus sign, DATEADD adds time instead of subtracting
Use negative numbers to subtract time, e.g. DATEADD('month', -1, [Date])
Mixing date fields and non-date fields in calculations
DATEDIFF and DATEADD require date fields for correct results
Ensure both fields used are date type or convert text to date before calculation
Summary
DATEDIFF calculates the difference between two dates in units like days or months.
DATEADD adds or subtracts a specified number of time units to a date.
Use exact date part keywords and correct data types for accurate results.