Quantcast
Viewing all articles
Browse latest Browse all 2697

A Solution to Tableau Line Charts with Missing Data Points

Image may be NSFW.
Clik here to view.
Continuous Line

A question that seems to come up every so often as a consultant is around how Tableau doesn’t show data where there is no data. Sounds kinda obvious, doesn’t it? But let’s frame this slightly differently and we can see that whilst this does make sense, it can be a bit of an annoyance.

Let’s take a look at a simple data set showing sales in June 2018:

Image may be NSFW.
Clik here to view.
Simple Sales Dataset

Two things to notice. Firstly, I’m English and live in Australia. Sorry to our U.S. friends, but I can’t bring myself to use your date format without dying inside a little. Secondly, not all dates are populated. We don’t have data against June 9, June 4 and a couple of other dates. So, if we plot this as a line chart in tableau we get:

Image may be NSFW.
Clik here to view.
Line Chart in Tableau

I have added Date to the label for clarity of what is going on. We can see that we have no data points at all for the missing days. This makes sense. Tableau isn’t inventing data, and having no data point is different than having a null value. But if we were a small retail outlet, for example, this lack of data is more than likely a day where there could have been sales but there happened to be none. In this case, it probably makes sense to consider these days as having 0 sales and the line chart should represent this. Looking at the chart above, unless we pay close attention, we don’t see that there were zero sales on June 9.

So, if we do want to see these dates without data as a date with zero sales, how do we do this?  Of course, we can use some ETL to update the source data. But if that’s not an option and this is a one-off piece of analysis, it’s likely over the top to write some ETL. So, can we make this work in Tableau? Yes! The obvious answer is to use the IFNULL function, and this would work great if our data looked like this:

Image may be NSFW.
Clik here to view.
Missing Data

But it doesn’t, so the IFNULL function won’t work as there are no nulls in the data. As mentioned above, we don’t have null values, we have no data. This is a critical and often misunderstood point.

The Solution

The trick is to use a table calculation, but of course, we don’t want to change any data values. So, we build a table calculation that pretty much does nothing other than saying to Tableau, “Hey, I’m a table calculation.” The reason for this is that this turns on data densification (where Tableau will essentially “fill in the gaps” in a date/time series). I have built a calculated field:

Image may be NSFW.
Clik here to view.
Tableau Calculation

The IIF expression will always return 1, so the result of this expression is the same as ZN(SUM([Sales])). Now if we add our original Sales field and the new calculated field to our worksheet we see the same thing:

Image may be NSFW.
Clik here to view.
Add Sales and Calc

So, what … it doesn’t work? Sorry, it does – stay with me. There’s just one more step. We need to click on the Date pill and select Show Missing Values:

Image may be NSFW.
Clik here to view.
Show Missing Values

With our new calculated field, we see a nice continuous line as opposed to the stop/start view of the original field:

Image may be NSFW.
Clik here to view.
Continuous Line

So, there we have it – a nice, quick and easy way to fill your data out and get a fuller picture of line charts. Of course, this should be used with caution. Sometimes having no data displayed is the right option. For example, if we were a retail outlet that was only open on weekdays we wouldn’t want our chart dropping to zero every weekend.

The post A Solution to Tableau Line Charts with Missing Data Points appeared first on InterWorks.


Viewing all articles
Browse latest Browse all 2697

Trending Articles