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 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?

In this example, double-click on the State/Province Dimension and change the Marks type from Automatic to Map, creating the following Map in Tableau. Otherwise, drag and drop Longitude to the Columns shelf and Latitude to the Rows shelf. For the remaining charts in Tableau, please refer to the Tableau charts.

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

The below 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.

DATEDIFF('day', [Order Date], [Ship Date])

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 1

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.

Calculate Date Difference in Tableau 4

The Date Difference calculated field automatically uses the SUM aggregate function by default. However, click the down arrow beside it and choose Average. Refer to the Get date from integer in Tableau article.

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.

Calculate Date Difference in Tableau 6

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

DATEDIFF function to Calculate Date Difference result