0
0
Tableaubi_tool~8 mins

Date calculations (DATEDIFF, DATEADD) in Tableau - Dashboard Guide

Choose your learning style9 modes available
Dashboard Mode - Date calculations (DATEDIFF, DATEADD)
Dashboard Goal

Understand how sales change over time by calculating the difference in days between order and ship dates, and analyze sales trends by shifting dates forward or backward.

Sample Data
Order IDOrder DateShip DateSales
10012024-01-012024-01-05250
10022024-01-032024-01-06450
10032024-01-072024-01-10300
10042024-01-102024-01-15500
10052024-01-122024-01-14150
Dashboard Components
  • KPI Card: Average Shipping Time (Days)
    Formula: DATEDIFF('day', [Order Date], [Ship Date])
    Calculation: Calculate days between order and ship dates for each order, then average.
    Result: (4 + 3 + 3 + 5 + 2) / 5 = 3.4 days
  • Bar Chart: Sales by Order Date
    Shows total sales for each order date.
    Formula: SUM([Sales]) grouped by [Order Date]
  • Line Chart: Sales Trend Shifted by 7 Days
    Formula: DATEADD('day', 7, [Order Date]) shifts order dates 7 days forward.
    Shows sales trend as if orders happened one week later.
  • Table: Orders with Shipping Delay
    Columns: Order ID, Order Date, Ship Date, Shipping Delay (Days)
    Shipping Delay Formula: DATEDIFF('day', [Order Date], [Ship Date])
Dashboard Layout
+-----------------------------+-----------------------------+
| Average Shipping Time (KPI) | Sales by Order Date (Bar)   |
|                             |                             |
+-----------------------------+-----------------------------+
| Sales Trend Shifted by 7 Days (Line Chart)               |
|                                                         |
+---------------------------------------------------------+
| Orders with Shipping Delay (Table)                       |
+---------------------------------------------------------+
Interactivity

A date filter allows selecting a range of order dates. When the user changes the date range:

  • The Sales by Order Date bar chart updates to show sales only for orders in the selected date range.
  • The Average Shipping Time KPI recalculates the average shipping days for orders in the filtered range.
  • The Sales Trend Shifted by 7 Days line chart updates to reflect sales shifted by 7 days but only for filtered orders.
  • The Orders with Shipping Delay table shows only orders within the selected date range.
Self Check

If you add a filter to show only orders with Order Date after 2024-01-05, which components update and what changes occur?

  • Average Shipping Time KPI: Recalculates average shipping days for orders from 2024-01-07, 2024-01-10, and 2024-01-12 only.
  • Sales by Order Date Bar Chart: Shows sales for 2024-01-07, 2024-01-10, and 2024-01-12 only.
  • Sales Trend Shifted by 7 Days Line Chart: Updates to show sales shifted by 7 days for filtered orders only.
  • Orders with Shipping Delay Table: Displays only orders with order dates after 2024-01-05.
Key Result
Dashboard shows average shipping time, sales by order date, and sales trends shifted by 7 days using date calculations.