KNOWLEDGE BASE

How to Color Part of the Specified Measure Conditionally When [Measure Value] Is Being Used in the View


Published: 08 Dec 2023
Last Modified Date: 20 Dec 2023

Question

How to color part of the specified measure conditionally when measure value is being used in the view.

For example,
the difference between the sales of Furniture and the sales of Technology is being displayed together with Furniture sales and Technology Sales by [Measure Value] and [Measure Name] as below.
How to color the difference value in red only when it's negative value while keeping the color of other bars as blue. 
User-added image

Environment

  • Tableau Desktop

Answer

1. Create a calculation field [Custom Color]
IF [Sales (Technology-Furniture)]>=0 THEN "Blue"
ELSE "Red"
END

2. Add the [Custom Color] to Color mark card.
User-added image

Notice that the bars of [Sales(Furniture)] and [Sales(Technology)] are also colored as well, which is unexpected.
User-added image

To fix it, move to step 3.

3. Add [Measure Name] to [Details] mark card first,
User-added image

Then change the type [Details] to [Color] by clicking the mark icon on the left of [Measure Name] on mark card.
User-added image

4. Double click on the color legend and set the color of [Red, Sales (Technology-Furniture)] to be red only, and the other item as blue.
User-added image

Click on [OK] to save the changes.
User-added image

Please check Sample-Color.twbx for details.

 
Did this article resolve the issue?