Two Colors for a Single Dimension Value in Tableau

For a recent Makeover Monday, I wanted to be able to visually focus on either the positive or the negative aspect of a metric based on the toggle of a parameter.  In particular, I wanted to be able to draw attention to the chosen aspect (positive or negative) by way of a bold color and turn the other portion grey without having to set up separate charts or worksheets.

As with many things in Tableau, this ended up being easier than originally thought.  It just took a couple of calculated fields and the realization that the same value can be given multiple names.

Here is what the view looked like when I was done.  The chart structure doesn’t change (other than the sort of countries) but the same portion of each chart (bar, donut, etc.) takes on a different color depending upon which parameter choice is selected.

The field I had initially used to construct my views was a fairly simple one that identified each response as either positive (“pos”) or negative (“neg”).  It’s also one that I borrowed shamelessly from Andy Cotrgreave’s viz…if someone else does something well, why not borrow it? 🙂

But when I placed it on the color shelf I was only able to assign one color to “pos” and one color to “neg”.

Since I knew I didn’t want to create two charts or duplicate the dimension, the main thing I needed to figure out was how to get the positive and negative values to play two roles, i.e. to be both highlighted and not highlighted depending on what parameter value was selected.  What solved the conundrum for me was the realization that the values of “pos” and “neg” were arbitrary…understandable and logical, but ultimately arbitrary.  I could just as easily have encoded the values as “captain” and “underpants” and the chart would have behaved the same way.  With that insight, I determined that I could encode the values one way when the first parameter value was selected and encode them another way when the second parameter value was selected.  Like so:

Now I have four distinct values within this dimension vs. just two.  The values still just represent the two response types of “positive” or “negative” but I’ve given each response type two discreet aliases.  This allows me to assign one set of colors to the values ending in “1”…

…and another set of colors to the values ending in “2”.
And with that I had the bulk of my desired viz created.  What remained was to create a few additional calculated fields to allow for a dynamic title…

…and to dynamically sort the countries based on either total positive or total negative responses:

I hope this short tutorial proves useful to others.  Thanks for reading.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s