Tableau Conditional Data Labels

One way to display labels based on the values of fields is to drag a measure to Label on the Marks card. However, you might find that you do not want to label every mark; rather, only the outliers, or only the data within your region. Using calculated fields, you can create conditional data labels based on a custom field that includes only the values of interest.
This article shows how to create a conditional label that appears on a mark only when a region’s sales for a day are greater than $100,000.

Set up the initial view

Complete the following steps to set up the view for the conditional labels.
  1. Open a new workbook and connect to the Superstore sample.
  2. From the Measures pane, drag Sales to the Rows shelf.
  3. From the Dimensions pane, drag Order Date to the Columns shelf, and then drag Region to Columns.
  4. On the Order Date drop-down menu, select Day.
  5. Hold down the Ctrl key and drag SUM(Sales) from Rows to Label on the Marks card.
The view should look something like this:

Create a conditional calculation

These steps continue from the view you created in the previous section, to build a conditional formula that describes which marks in the view to label.

Step 1

Select Analysis > Create Calculated Field.

Step 2

In the Calculated Field dialog box, complete the following steps.
  1. For Name, type Outliers.
  2. In the Formula box, build the following formula:IF SUM([Sales])> 100000 THEN
    SUM([Sales])
    ELSE null END

  3. Confirm that the status message indicates that the formula is valid, and then click OK.

Step 3

From the Measures pane, drag Outliers to Label on the Marks card, replacing Sales.

Step 4

If necessary, format the numbers as currency.
The view now includes labels only where sales are greater than $100,000.
Tip: You can show or hide the labels for individual marks. To hide a specific data label, right-click the mark and selectMark Label > Never Show.

Learn more

To learn more, search for context filters in the Tableau Desktop Help.