This post will compare different date ranges on a single axis using Tableau.
Last week, a client asked me if it was possible to make only one single graph. He wanted to select two different date ranges for comparison reasons. The date granularity was also a must have. Really? All these features just in one graph? I started working on this and the result was rather satisfying. Et voilà, the reason for my first blogpost!
First of all, the data used in this tutorial is the orders tab in the EU Superstore dataset. Let’s start by making a flexible axis so the date granularity can be chosen.
- Create a parameter (in my example “Choose Granularity”) with the date granularity.
- Create a calculated field (in my example “Date Granularity”) with following code:
- Convert “Date Granularity” to discrete and to dimension. Drop this in the Columns shelf. Show the parameter “Choose Granularity”. Try for yourself if the axis changes when you change the parameter. Does it work? Check! Yay! Part One of the challenge completed!
- Now for the more difficult part. How is it possible to compare two date range on one single graph? Let’s kick off by creating 4 different parameters (indeed four, vier, quatre, cuatro,…)! The parameters should all be dates. I’ve chosen an unlimited range with a step size of 1 day. Name the four parameters “StartDate 1”, “Startdate 2”, “Enddate 1” and “Enddate2”.
- Create 2 different calculated fields for the date ranges. I have called them “Date Range 1” and “Date Range 2”.
- Drop these 2 calculated fields (“Date Range 1” and “Date Range 2”) on the Rows shelf. Plot the on one axis using the dual axis function in Tableau, synchronize the axis and give a different color to the two ranges. Show the four parameters. Set the first date range by setting StartDate 1 and EndDate 2 and the second date range by setting Startdate 2 and EndDate 2. After you’ve done this, you should a similar result as this. This should work like a dream.
Done! 2 Different date ranges on 1 single axis (graph) and the possibility to choose the granularity. You can download the example workbook on Tableau Public by using the below link. Check also the Youtube video where you can see the creation of this sheet in action! Feel free to share!
Tableau Public Link: