KNOWLEDGE BASE

Conditionally Color Text Marks


Published: 04 Apr 2014
Last Modified Date: 08 Feb 2020

Question

How to conditionally color the text marks in a crosstab, text table, or view.

Environment

Tableau Desktop

Answer

CLICK TO EXPAND SOLUTION

Option 1: Color each number as over/under a threshold

This method uses a divergent color palette to color text based on whether it is over or under a threshold.

These directions assume the view is already built. For an example with directions from scratch, see the "Opt 1: Divergent Color Palette" worksheet in the workbook in the right-hand pane of this article.

Example 1: Create calculated fields for each measure used

  1. Drag the desired measure to Color on the Marks card. Note: if the view has multiple measures, then drag [Measure Names] onto Color.
  2. Click Color on the Marks card and click Edit Colors....
  3. In the Edit Color dialog, do the following and click OK
    1. For Palette, pick a diverging color palette
    2. Check Stepped Color and choose 2 steps
    3. Optional: Click Advanced >> and/or check Center and type in the desired threshold value
To view the steps showed in the below video, please expand the above section.
Note: the video has no sound.
CLICK TO EXPAND SOLUTION

Option 2: Color each number based on its own value

Separate color legends is a feature added in Tableau Desktop 10.2 that allows each measure in a view to be colored by a continuous scale based on its own value.

These directions assume the view is already built. For an example with directions from scratch, see the "Opt 2: Separate Legends per Measure" worksheet in the workbook in the right-hand pane of this article.

  1. Drag [Measure Values] from the data pane onto Color on the Marks card
  2. On the Marks card there will be two green [Measure Values] fields, one with the "T" icon for Text and the other with the four colored dots icon for Color. Right-click the [Measure Values] with the Color icon and select Use Separate Legends
  3. Right-click the color legend for the first measure (on the legend itself, not the title) and select Edit Colors…
  4. In the Edit colors dialog, select the desired color palette and options
  5. Repeat steps 3-4 for every measure
Optional: Format a measure with the standard gray:
  1. Right-click the color legend for a measure, and select Edit Colors…
  2. In the Edit colors dialog, do the following and click OK:
    1. For Palette, select Custom Diverging
    2. Check Stepped Color, and select 2 Steps
    3. Click the starting color box
    4. In the Select Color dialog that appears, for HTML type in #333131
    5. Repeats steps c & d for the ending color box
  3. Click the down carrot in the top right-hand corner of the SUM(Sales) legend, and select Hide Card
CLICK TO EXPAND SOLUTION

Option 3: Color number values based on other discrete fields

Multiple discrete fields can be added to Color on the Marks card, and then each combination of values can be colored differently. This method has a lot of flexibility as it can allow each measure to be colored by a different calculated field.

These directions assume the view is already built with a calculated field that determines color called [Color KPI]. For an example with directions from scratch, see the "Opt 3: Multiple Discrete Fields on Color" worksheet in the workbook in the right-hand pane of this article
  1. Drag [Color KPI] onto Color on the Marks card
  2. Drag [Measure Names] from the data pane to Detail on the Marks card
  3. Click the Detail icon next to the [Measure Names] field on the Marks card and select Color
  4. Click Color on the Marks card and select Edit Colors…
  5. In the Edit Colors dialog, select the desired color for each combination of discrete field values
To view the steps showed in the below video, please expand the above section. Note: the video has no sound.
CLICK TO EXPAND SOLUTION

Option 4: Color each column separately

This method has the most flexibility, but is also the most complicated to set up. This is the only option that will allow dimension values to be conditionally colored. These directions are demonstrated in "Opt 4: variation (only measures)" worksheet in the workbook in the right-hand pane of this article.
Step 1: Create calculated fields for each measure used
  1. For every measure that you want to include in the view, select Analysis > Create Calculated Field.
  2. Name the field. Consider including the name of the measure in it. For example, Sales Col.
  3. In the Formula field, type 0, and then click OK.
Step 2: Build the view
  1. Drag Region and Order Date to Rows.
  2. Drag Segment to Columns.
  3. Drag each calculated field that you have created to Columns.
  4. In the ALL Mark cards, ensure the Text is selected as a Mark Type.
  5. In each mark card, drag the associated measure to Text and to Color. For example, drag Sales to Text in the SUM(Sales Col) mark card. 
  6. Modify the color of each measure as desired.
  7. Right-click each measure on the axis and select Edit Axis
  8. Navigate to the Tick Marks tab > select None for Major tick marks and Minor tick marks, and then click OK.
  9. In the Rows, right-click any of the calculated field and select Format
  10. Click the Lines icon and navigate to the Columns tab. 
  11. In the Zero Lines drop-down menu, select None.
  12. In the Grid Lines drop-down menu, select None.
Step 3: (Optional): move titles to the top
  1. For each desired column in the finished crosstab, drag two copies of the calculated fields created in the directions above to Columns.
  2. Drag the desired measure to Text in both copies of the calculated field.
  3. Right-click on the second copy of the calculated field on the Columns shelf and select Dual Axis.
  4. Edit both the top and bottom axes as desired.
To view the steps showed in the below video, please expand the above section. Note: the video has no sound.

Additional Information

Options 1-3 can only color measure values. Option 4 can color both measure and dimension values.

By design, Tableau Desktop does not apply color to dimensions. Restricting color to measures is one way to focus the viewer on the data in the view rather than on the headers. Therefore to color dimensions in a crosstab, we must place the dimension values in "container" calculated measures.

Color can be applied either to the text or background of row/column field labels (aka row/column headers) via the formatting options Format Fields and Field Labels. Currently the ability to apply a conditional color to field labels is not currently built into the product

Notes on Option 3
  • [Measure Names] cannot be used in a calculated field, which is why it is necessary to add [Measure Names] to Color as well as the calculated field to determine color
  • When multiple discrete fields are added to color on the Marks card, then Tableau Desktop will automatically nest the colors. The first discrete field on Color is assigned a different color (blue, orange, green, etc…) and then every value for the next discrete field is given a different shade of those colors. If colors are changed, you can always get back to this default by hitting "Reset" in the Edit Colors dialog.
  • The color legend created may not be very readable. In this case, consider creating a color legend as in Creating Legends that Apply to Multiple Sheets
Notes on Option 4:
  • It is not necessary to create multiple "Col" fields, but makes it easier to tell the multiple Marks cards apart because Marks cards are named based on the name of the field.
  • To quickly open a particular Marks card, click on the green measure on the Columns shelf, or click on the axis header in the view.
  • All measure columns must be the same width.

Discuss this article... Feedback Forum
Did this article resolve the issue?