KNOWLEDGE BASE

Conditionally Colour Text Marks


Published: 04 Apr 2014
Last modified date: 20 Jul 2023

Question

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

Environment

Tableau Desktop

Answer

CLICK TO EXPAND SOLUTION

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

This method uses a divergent colour palette to colour 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 Colour 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 Colour on the Marks card. Note: if the view has multiple measures, then drag [Measure Names] onto Colour.
  2. Click Colour on the Marks card and click Edit Colours....
  3. In the Edit Color dialog, do the following and click OK
    1. For Palette, pick a diverging colour palette
    2. Check Stepped Colour and choose 2 steps
    3. Optional: Click Advanced >> and/or check Center and type in the desired threshold value
To view the steps shown in the below video, please expand the above section.
Note: the video has no sound.
CLICK TO EXPAND SOLUTION

Option 2: Colour each number based on its own value

Separate colour legends is a feature added in Tableau Desktop 10.2 that allows each measure in a view to be coloured 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 Colour 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 coloured dots icon for Colour. Right-click the [Measure Values] with the Colour icon and select Use Separate Legends
  3. Right-click the colour legend for the first measure (on the legend itself, not the title) and select Edit Colours…
  4. In the Edit colours dialog, select the desired colour palette and options
  5. Repeat steps 3-4 for every measure
Optional: Format a measure with the standard grey:
  1. Right-click the colour legend for a measure, and select Edit Colours…
  2. In the Edit colours dialog, do the following and click OK:
    1. For Palette, select Custom Diverging
    2. Check Stepped Colour, and select 2 Steps
    3. Click the starting colour box
    4. In the Select Colour dialog that appears, for HTML type in #333131
    5. Repeats steps c & d for the ending colour 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: Colour number values based on other discrete fields

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

These directions assume the view is already built with a calculated field that determines colour called [Color KPI]. For an example with directions from scratch, see the "Opt 3: Multiple Discrete Fields on Colour" worksheet in the workbook in the right-hand pane of this article
  1. Drag [Colour KPI] onto Colour 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 Colour
  4. Click Colour on the Marks card and select Edit Colours…
  5. In the Edit Colours dialog, select the desired colour 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: Colour 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 coloured. 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 Colour. For example, drag Sales to Text in the SUM(Sales Col) mark card. 
  6. Change the colour 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 colour measure values. Option 4 can colour both measure and dimension values.

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

Colour 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 colour 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 Colour as well as the calculated field to determine colour
  • When multiple discrete fields are added to colour on the Marks card, then Tableau Desktop will automatically nest the colours. The first discrete field on Colour is assigned a different colour (blue, orange, green, etc.) and then every value for the next discrete field is given a different shade of those colours. If colours are changed, you can always get back to this default by hitting "Reset" in the Edit Colours dialog.
  • The colour legend created may not be very readable. In this case, consider creating a colour 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.
Did this article resolve the issue?