console.log("script ran")

dashboard / LEARN / Other / Tableau

Display variances between dates

2020-08-06

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.

 

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

 

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

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

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

14 likes

Author

Ivett Kovács

I love taking datasets into beautiful and informative visualizations. Besides data, I am also very passionate about traveling, surfing, cooking and exploring the outdoors with my dog.

Your email address will not be published.