Version(s): 8.0, 7.0, 6.1
Last Modified Date: 16 Aug 2016
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.
Create the initial view
Complete the following steps to set up the view for the conditional labels.
- Open a new workbook and connect to the Superstore sample.
- From the Measures pane, drag Sales to the Rows shelf.
- From the Dimensions pane, drag Order Date to the Columns shelf, and then drag Region to Columns.
- On the Order Date drop-down menu, select Day.
- 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.
Select Analysis > Create Calculated Field.
In the Calculated Field dialog box, complete the following steps.
- For Name, type Outliers.
- In the Formula box, build the following formula:
IF SUM([Sales])> 100000 THEN
ELSE null END
- Confirm that the status message indicates that the formula is valid, and then click OK.
From the Measures pane, drag Outliers to Label on the Marks card, replacing Sales.
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 select Mark Label > Never Show.
To learn more, search for context filters in the Tableau Desktop Help.
Alternate Search Terms:How To Calculations mark label annotate annotations format