Introduction
There are times when I need to use a simple technique for reducing data label density along a line in Tableau. I do this by showing only the Nth data label along a line by using a mathematically-based filter coupled with a specific data label prepared as a calculated field. In this article, I show how this is done.
This article extends work I published about three years ago. The article that forms the foundation of the current techniques can be viewed here.
The Problem Is That There Are Too Many Labels
Figure 1 shows a typical figure that I create for many applications. The labeling I use for the cumulative curve (the right-hand axis) is too dense for my liking. I want to label only every Nth point along that curve. I’m too lazy to manually select every Nth data point to label so I just use the technique shown in this article to accomplish the task.
The Solution Should Have Fewer Labels
Figure 2 shows an alternative in which every 2nd data label is shown along the cumulative curve. In general, a parameter can be picked to show every Nth label.
Figure 2 – There are now fewer data labels along the cumulative curve line. I chose to plot every 2nd data label.
The following video explains the method I use to do this work.
The Formulas
Here are the four simple steps needed to do this:
- Create an integer parameter called [Nth label]
- Crete a calculated field called [Index] = index()
- Create a calculated field called [Keeper] = ([Index]+([Nth label]-1))%[Nth label]
- As shown in Figure 4, create a calculated field that holds the values you want to display. In my case, I called it “Running Sum Label”, as
- If([Keeper]=0) then
running_sum(COUNT([Distance (mi)]) / TOTAL(COUNT([Distance (mi)])))
end
- If([Keeper]=0) then
Additional Functionality
Although you can change your bin settings to change the look and feel of your histograms, you can also use the keeper formation as a filter to plot every Nth bar of the histogram. It can be used to create interesting plots, such as Figure 4. Figure 4 shows both the bars and labels being placed for every Nth data point.
Final Thoughts
Even with all of the versatility built into Tableau, there is always room for developing some creative mathematical approaches. By documenting simple techniques like this, I have been able to customize many figures through the years to achieve special desired effects.
This technique can even be used to create alternating colors in the histogram, as shown in Figure 5. This seems to break up the monotony of the histogram somewhat. Can you think of how this was accomplished?
Finally, you can always find my Tableau articles by clicking on this link. There are many articles like this one that help you to think outside of the box when working in Tableau.