How to Label Only Every Nth Data Point in #Tableau

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.

Label_1_point

Figure 1 – There are too many data labels along the cumulative curve line. I want to reduce the number of labels along the line.


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.

 

Label_2_point

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:

  1. Create an integer parameter called [Nth label]
  2. Crete a calculated field called [Index] = index()
  3. Create a calculated field called [Keeper] = ([Index]+([Nth label]-1))%[Nth label]
  4. 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
    1. If([Keeper]=0) then
      running_sum(COUNT([Distance (mi)]) / TOTAL(COUNT([Distance (mi)])))
      end

Running_sum_label

Figure 4 – The specially prepared data label field that uses the keeper calculation to populate the data labels.


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.

Label_2_point_and_bar

Figure 4 – Both the bars and labels are shown for every 2nd data point. This is accomplished by picking only the 0th element of the keeper filter when the Nth label parameter is set to 2.


 

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?

Label_4_point

Figure 5 – By placing the keeper filter on the color shelf, you can create multiple color bands in your histograms! It’s a little bit of an optical illusion in this case.


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.

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.