Display variances between dates
Written by: Ivett Kovács
![Variances between dates](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2Fdd2c516165c22af0d4d160a4705807f0ffe42d50-1200x688.gif%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=75)
Learn how to easily display changes between dates using Tableau in this blog post. With step-by-step instructions and the Superstore dataset, you can replicate this powerful solution quickly. See the surprising results for yourself!
A quick note: This post was originally published some time ago on DataViz.Love, our old blog. We have moved it here for preservation with the approval of the author(s).
In this post, I would like to show how you can display changes between dates.
To be honest, I got the idea from an Excel example but let’s focus on Tableau for now.
I tweeted this gif on my Twitter, but I think the best way is to present the solution on the Superstore dataset so you can easily replicate it too.
![Date variances gif](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2Fdd2c516165c22af0d4d160a4705807f0ffe42d50-1200x688.gif%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
Step #1: Show sales on a bar chart per month
- After you connect to the Superstore data, add Order Date to Columns. Depends on what you want to show, select a Continous Date. I used Month Continous Date.
- Add Sales to Rows
- Add Year(Order Date) to Filter
![Show sales on a bar chart per month](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2Ff63755ff15ad6cc2d24b483b8827b8a6c609ba18-1980x856.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
Step #2: Create fake date field
Fake Date
DATETRUNC(‘month’, [Order Date])+15
Why did I add 15? On average, 1 month is 30 days long so in order for the variance line to be between 2 months, the fake x-axis must be shifted by 15 days (30/2).
Note:
If you have years:
DATETRUNC(‘year’, [Order Date])+182
If your date is an integer data type:
[Date]+0.5
- Put this Fake Date next to the Month(Order Date) field in Columns
- Select Dual Axis
- Synchronize it
- Set Gantt bar on the second Mark
- Then hide the axis of Fake Date
![Creating fake date field](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2F88df5e4c8a0d6e787bd4ab531e967e32afd5b9f6-1780x1102.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
Step #3: Calculate the variance between dates
Variance
(ZN(SUM([Sales])) – LOOKUP(ZN(SUM([Sales])), 1))*(-1)
- Put the calculation to Size of the Gantt bar
- You can use this calculation or Variance% calculation on Label
- Plus you can use color to highlight the direction of change
![Calculating the variance between dates](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2Fc5abc3d76fcc91f16b4087e48c11f3cdfe50a13b-548x330.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
![Calculating the variance between dates - continued](/_next/image?url=https%3A%2F%2Fcdn.sanity.io%2Fimages%2Fgj1oqiyh%2Fproduction%2F963f6da09af3f444871a67569c77a0e5262ebe87-1744x1080.png%3Fq%3D100%26fit%3Dmax%26auto%3Dformat&w=1536&q=100)
That’s it! I think it’s surprising how quick, simple, and powerful solution it is.
If you have any questions, reach out on Twitter @IvettAlexa