Ryan Sleeper
This video shares how to make a timeline in Tableau and how to add an optional reference line to display the current day.
Hi, this is Ryan with Playfair Data TV. And in this video, I’m going to show you how to make a linear timeline in Tableau. By the end of this video, you’ll be able to make a chart type that looks similar to what you see on the screen here. This is showing events over time, and there is a reference line showing you today’s date, which we’ll update in real time.
This is a great chart selection for adding context to a line graph. Perhaps you see a spike or a dip, and you can use, kind of, a calendar timeline like you see here to provide context to your end users that something happened on those dates to drive those changes in the business.
You can make these timelines out of any dates you want, of course, but we will be using the Sample – Superstore dataset so that you can follow along. So over here in Tableau Desktop, I’m going to make one change to the default Sample – Superstore dataset so that we can all follow along together if that’s of interest to you. And that involves the date field.
The Sample – Superstore dataset currently only runs through the year 2019, but I am recording this video on July 26, 2020. So what I’m going to do, so that this feels more real world and more real time, I’m going to create a calculated field out of the Order Date dimension by right-clicking on it and then hovering over Create and selecting calculated field.
And I’m going to call this Order Date Plus 365, and that actually is the entire formula. I’m just adding a year’s worth of days so that it runs through 2020 instead of only running through 2019. I will click OK.
The first step to creating a linear timeline in Tableau is we need to create that consistent baseline. And this is yet another application of one of my favorite tactics in Tableau, which is to create what I call a placeholder field. The formula that I always use is the aggregation of MIN, M-I-N 0.
I use this so often that I usually make a calculated field with that formula, MIN 0, but this is another example of how you can use Tableau in the flow, is what it’s called. So a shortcut to creating that baseline is I can just double click on the Rows Shelf and type in that whole formula.
The aggregation M-I-N, open parentheses, 0, close parentheses, click enter, and we’ve got this baseline. On the Rows Shelf, we just basically created a fake y-axis, which value always equals 0. So as we add dates in here, they’ll all be steady on a single line. One advantage to using the number 0, by the way, is it provide some flexibility in how you format that even baseline.
Because all of the values are at 0, you can simply format your 0 lines, and that way you can format that baseline as a dash line. You can change the color, change the weight of it, et cetera. Now that we’ve got our baseline, we’re going to break it down by that Order Date Plus 365 field.
Again, you can create this with any dates that you’d like in your business and at any granularity, but I’m personally, for this example, going to right-click on Order Date Plus 365 while I drag it to the Columns Shelf, and I’m going to choose the first option. This will create a data point at every single date in my data set. So I’ll click OK.
There’s quite a bit in here, so I’m also going to filter it to just the current month that I’m recording this video in. So I’ll drag Order Date Plus 365 to the Filters Shelf, choose Month Year, and filter it to just July 2020. Click OK. And we’re seeing just a flat line at this point. That’s because the mark type is line. So I’m going to change the mark type to circle just so that we can see those individual data points a little bit better.
And again, I’m using the Sample – Superstore dataset so that you can follow along. But in the real world, you probably don’t have an event every single day like you’re seeing here. So one more step to make this a little bit more realistic, I’ll drag the Order Date Plus 365 field onto the Filters Shelf again. This time I’ll choose Weekdays, and just limit it to a few days of the week. I’ll just pick a few random days here– and Thursday.
So four out of my seven days, I’ll click apply to see how that looks. We should see a few more gaps. Let me see if I get rid of Tuesday– still feels like we have quite a few. All right, I’ll call that good for now. Three out of our seven days. I’m just pretending that those are events in my business.
If you apply these same principles to your own dataset, you’ll probably see a pattern that makes a lot more sense and has a little bit of distribution, a little bit better distribution than the sample dataset. So there is my linear timeline. I might put this on top or at the bottom of a line graph to show my audience when an event happened in our business that drove performance.
But there’s one extra nice feature that we can add to this, which is a reference line showing us where we’re at today. So that way we can see what events have passed and what events are coming up. To do so, we need a calculation that uses the function T-O-D-A-Y, TODAY. Again, just like my placeholder field, one option is to make a calculated field out of that.
But we can also use Tableau in the flow for this by just double clicking in any blank space on the Marks Shelf and typing this formula– T-O-D-A-Y, that’s a function, open parentheses, close parentheses, and click enter. That will always look at today’s date, so it is July 26, 2020. What’s nice about that formula is it is dynamic. It will update as our days progress. That Today will be recomputed and it will always be today’s date.
Want to show you one little pitfall with this because we’re not quite done setting up that field. I want to add Today as a reference line, but with its current setup, a discrete dimension like that, it will not be available to me on a continuous axis, which is what I have here on the x-axis.
Just to prove that, I’m going to right-click on the axis and choose add reference line. And if I use this dropdown for values, I will see all of the fields that are available to me to add as a reference line. As you can see, we could add a reference line for Order Date Plus 365, but we don’t see Today. So it’s not even available to us yet.
The trick that you just have to remember if you want to show a reference line for today’s date is you need to click into this pill. Make sure that this is the exact date. It should be chosen– it should be selected that way by default so you should be good there, but then we also need to convert this to a continuous field. That will turn it green.
And now if I go add a reference line to this continuous axis, we should see that continuous Today field as an option, and we do. I’ll click Today. We should see that update in real time. As I mentioned, it’s July 26, and sure enough, we have a reference line drawing across the entire view on July 26. I’ll click OK.
And I’ll do just a few more things to clean this up. This y-axis is meaningless. That’s my 0 baseline. That number doesn’t mean any anything to the audience. So I’m going to right-click on that header and de-select Show Header. I’m also going to update the label. Instead of Minimum Today, I’m going to edit this reference line and change the label to something custom.
I’ll just type in TODAY in all caps, that way my audience knows that line represents today’s date. I’ve never loved the headers or the titles rather when I’m using dates. You can also get rid of that by right-clicking on the axis. Click edit axis, and then simply delete the title altogether. Just remove everything in there and then the title will go away.
I’ll drag this towards the top so it’s a little bit more streamlined. And then one last little tip I’ll share with you, that 0 baseline, as I mentioned, one of the benefits of choosing 0 as the number is that dashed line is simply a 0 line. And that’s one of the types of lines that you can format in Tableau by right-clicking anywhere on the view and choosing format.
And if I go to this last tab, four lines, one of the options is 0 lines. As you can see, by default, we have a thin dotted line, but maybe I’d want to go with the heavier weight. And instead of dotted, I’ll make it a solid line. Instead of the default gray, I’ll make it red, and just a format that a little bit more.
That’s been a linear timeline in Tableau. I really like that as a tactic to add context to my line graphs. If you’re in a business that might have more than one event per day, we have a separate video here at Playfair Data TV that shows you how to make a timeline, actually two ways to make a timeline when events overlap and I encourage you to check that one out.
This has been Ryan with Playfair Data TV – thanks for watching!