Calculate the Date Difference in Tableau

This Tableau article shows the steps in calculating the Date difference between the Order date and ship date in each state with an example.

To demonstrate the Tableau Date Difference Calculation, we used the Sample Superstore Excel sheet. Please visit the Excel Source article to understand the Data Source.

How do you calculate the date difference in Tableau?

Double-click on the State/Province Dimension and change the Marks type from Automatic to Map, creating the following Map. Otherwise, drag and drop the Longitude to the columns shelf and the Latitude to the Rows shelf. For the remaining charts in Tableau, please click here.

Create a Map using State names

Tableau has a DATEDIFF function to calculate the difference between two dates. To use this DATEDIFF function, we must create a calculated field to write the DATE expression. So, click the Analysis Tab and choose the Create Calculated Field option.

DATEDIFF('day', [Order Date], [Ship Date])
Create a Calculated field to write DATEDIFF function

The above Tableau expression will find the difference in days between the Order date and the Shipping date. For months difference, replace day (in the first argument) with month.

Please drag the newly created Date Difference calculated field to the Color Shelf. Next, click the down arrow beside it to Edit Colors.

Calculate Date Difference in Tableau 3

Let me change the Palette to the Red-Green-Gold Diverging color with a full-color range in reverse order. It means fewer days to shop from the order date, green color, and for the Loner days, gold color.

Change the Map Colors

The Date Difference calculated field automatically uses the SUM aggregate function by default. However, click the down arrow beside it and choose the Average.

Calculate Date Difference in Tableau 5

The Tableau map below shows the exact day difference between the hire and ship dates. Next, set the Washout percentage to 100 to remove the background. You can play with the Background Map Layer and Data Layer options.

Tableau DATEDIFF function to Calculate Date Difference

Use the control or Command key to select the AVG(Date Difference) in the color shelf and add it to the Label shelf.

Tableau DATEDIFF function to Calculate Date Difference result