See all tips | View as pdf

Conditional Data Labels

You may have already figured out that you can place a field on the Text shelf to add data labels based on the values of that field. However, often you'll find that you don't actually want to label every mark; rather you may want to label only the outliers, or only the data within your region. Using Tableau's calculated fields you can create conditional data labels based on a custom field that only includes the values of interest.

Here's how it works.

Say you are analyzing the daily regional sales for a supermarket and you want to label all regions that have sales greater than $130,000. Dragging the Sales Total field to the text shelf, adds data labels based on the total sales for each region.
Placing Sales Total on the Text shelf adds labels based on the Sales Totals for each region.

To add conditional data labels:

1. Select Create Calculated Field on the Measures Data window menu.
Select Create Calculated Field on the Measures Data window menu.
2. In the Calculated Field dialog box, name the field "Outliers" and write a conditional formula that describes the marks you want to label. For example, the formula to only label regions whose sales is greater than $130,000 looks like this:
IF SUM([Sales Total])>120000 THEN SUM([Sales Total]) ELSE null END
The Calculated Field dialog box should look something like this:
Image of the calculated field dialog box containing the formula mentioned above.
3. Place the new field on the Text shelf.
Place the new field, Outliers, on the Text shelf.
The final view only includes data labels for the regions whose sales are greater than $130,000.
Image of the same view we started with, but this time using conditional data labels.
Note: If you are using Tableau v3.0 or later, you can show and hide the data labels for individual marks. To hide a specific data label, right-click a mark and select Data Labels > Off.
Right-click a mark and select an option on the Data Labels menu.
 

To Learn More

  • Learn more about data labels by searching for Data Labels in the Tableau Online Help.
  • Contact Tableau Technical Support at: (206) 633 3400 x2
  • Learn this trick and many more at the Tips and Tricks index. Don't forget to bookmark it.