KNOWLEDGE BASE

Conditionally Colour View by Each Value or All Values Combined


Published: 24 Sep 2018
Last modified date: 20 Jul 2023

Question

How to colour marks differently for each dimension member, or another non-segmented colour when all dimension members are shown in the view

Environment

  • Tableau Desktop

Answer

The attached example workbook uses the sample data set Superstore to demonstrate the following directions:
  1. Drag [Region] to the Columns shelf
  2. Drag [Sales] to the Rows shelf
  3. Drag [Profit] over the axis for Sales and drop the field
  4. Move [Measure Names] from the Columns shelf to Colour on the Marks card
  5. Create a calculated field with a name like "All or each segment colour" with a calculation similar to the following:

    IF { FIXED : COUNTD([Segment])} = {EXCLUDE [Segment] : COUNTD([Segment])}
    THEN "All"
    ELSE [Segment]
    END

    Note: The FIXED expression will always return the total unique count of segments no matter how the view is filtered. The EXCLUDE expression will return the unique count of segments in the view based on how the view is filtered. It is necessary to exclude [Segment] otherwise each mark in the view will return 1 (since each bar segment only has one value of [Segment])

  6. Shift-drag [All or each segment colour] to Colour.

Additional information

It will be necessary to change the [Segment] filter and manually set the colour for that filter selection. And then repeat this process for every possible [Segment] filter selection.
Did this article resolve the issue?