top of page
Search
Writer's pictureVani Agarwal

How to color code different measures based on different conditions?

To keep things simple, I've used the superstore data to explain how to color code different measure values separately.


Below is my view where I've 4 measure value against my sub-categories and I need to color code sales and profit values and keep the quantity and discount values black (default color).


The condition for color coding is different for both sales and profit.

Sales - Color the values green if they're above $1,50,000 and red if less than $1,50,000.

Profit - Color the negative values green and positive values red.


To do so, I first need to create calculated fields for my above conditions.

For sales, the calculated field will be

#Sales Color ---> 'IF sum([Sales])>150000 THEN "Green" ELSE "Red" END'

#Profit Color ---> 'IF sum([Profit])>=0 THEN "Green" ELSE "Red" END'


Now, we need to put the above 2 calculated fields in our marks card on color shelf.




The above result is not at all what we wanted. This is because, we have just put color codes on our color shelf but failed to tell tableau on which measure should the color code be applied to. By default, it's getting applied to all the measures in the view.


To solve this, we need to bring our measure names also onto our color shelf.

Important thing to note here is the order in which the dimensions are places on the color shelf.

As soon as we put the measure names above our color codes, we can see the colors for each measure now which can we customized as per our needs.


Now, let's understand the colors first.

Since we have placed sales color code above profit in our color shelf, the color codes are also appearing in the same order.


Let's understand this with few of the above color codes.

Sales, Green , Green - Sales comes from the measure name which is in the 1st position in our marks card. Second which is Green comes from our calculated field of Sales Color and it means that our value is above $1,50,000 hence Green color code.

The 3rd one which is Green comes from our Profit color code calculated field and it means that our profit value is >0.


So now, I'll click on each of the color codes and give them the colors as required.


After selecting the colors for each color code, we now get our desired result. (The colors are selected by either going on colors in the marks card or by double clicking on color legends on the right)


(Note : To add multiple dimensions in color, add them on details first and then click on the sign on the left side of each dimension in the marks card and change them to color.)


Thank you for reading. You can reach out to me on any of my social media handles and I will be more than happy to discuss and doubts or suggestions.



665 views0 comments

Recent Posts

See All

Comentarios


Post: Blog2_Post
bottom of page