If you’re coming from Excel, manipulating colors in Tableau can feel unnecessarily complicated, especially while you’re learning.
In Excel, changing the color of a column is as easy as highlighting and right-clicking the cells you want to change.
However, colors in Tableau are usually modified at the data level. The methodology depends on whether you’re coloring a dimension or measure.
In short, to change the color of only one column, you need to either (1) isolate a target measure in the view and drag a corresponding dimension or measure to the color mark, (2) use mark types “bar” and “square” plus the color mark on measures, (3) format a dimension to the desired color and eliminate row banding, or (4) use IF statements to create new dimensions for coloring purposes.
This article shows the following colorization examples:
- measure text based on a dimension (cross-tab),
- measure cells based on a dimension (cross-tab),
- measure text based on the measure (cross-tab),
- measure cells based on the measure (cross-tab)
- dimension text based on IF statement (cross-tab),
- dimension cells based on formatting (cross-tab),
- columns in a column chart by dimension,
- bars in a bar chart by dimension,
- lines in a line graph by dimension, and
- spaces in an area chart by dimension.
Once you’ve seen these examples, you’ll be able to change colors on all visualizations.
I’ll be using the Tableau Bookstore database, which you can download here. In addition, you can view and download all the Tableau worksheets used in the article at the AnalystAnswers.com page on Tableau Public.
Make Sure Your Formatting Skills are Strong
Tableau’s visualizations are only as strong as your formatting skills. So make sure you understand the various ways of coloring a single column. But don’t stop there. Cover all the essential formatting with our Tableau Quickstarter, or take the free [qsm_link id=1]Tableau knowledge quiz[/qsm_link] to see what you know!
Color a Column in a Cross-tab
There are two ways to coloring a column. The first is coloring the text itself, and the second is coloring the cell background.
We’ll look at both of these colorizations for measure and dimensions.
Measures Based on a Dimension
Measures are easier than dimensions because Tableau is constructed to color them first. We’ll start here and move to dimensions next.
Text
Imagine we have a cross tab of book ISBNs, the first and last name of the author, the book title, and it’s price. We then place a count of order IDs (measure) to see how many times each book was purchased.
To color the text of order ID based on a dimension, such as Price, it’s as easy as dragging another instance of the Price dimension to the color mark, as you see above.
Cells
To color the background of the cells and not the text, you need to change the mark type of the CNT(Order ID) from Text to Square and maximize the size of the mark. This will produce the following result.
Measures Based on a Measure
Text
A similar methodology applies for coloring measure text based on a measure. It consists of dragging the display measure to the text mark and dragging the coloring measure to the color field. It looks like this:
Here I’m using the same measure as the text and the color, but you could use any measure you want for applying colors.
Cells
A similar methodology applies for coloring cells based on measures as on dimensions. You simply need to change the color mark type to a square and maximize its size. It will produce the following results:
Note that the colors based on measures are not discrete. The default is a spectrum. When you only want two colors, you’ll click on the color mark, select Edit Colors…, choose Palette > Custom Diverging, choose 2 steps, and choose the colors you want.
The default setting will cut the range into two and color each “half” of the range with the respective colors your chose. You can, however, choose “Advanced >>” and set the starting and end points.
If you want to set colors based on special conditions, this will require a calculated field with an IF statement. For example, if you want to color all values greater than 10 red and all values less than 10 blue, this means you’ll need to create a dimension. Let’s look at this now.
Dimensions Based on IF Statement
When you want to color a dimension based on special criteria, you will need to create an IF statement calculated field. For example, imagine we want to color the cells of authors whose last names start with the letter B.
Text
We start by creating the following calculated field:
Now we need to copy the last name dimension and convert it to a measure. You do this by right-clicking the Last Name pill > Duplicate. Then, on the copy pill, click “Convert to Measure.”
Place the measure in the text box and convert the aggregation from “SUM” to “MIN,” then place the “Color Author Names B” calculated field on the color mark. This will produce the following result:
Cells
To change the colorization from text to coloring the background of each cell, simply change the mark type from text to square and maximize the size. It will look like this:
Dimensions Based on Formatting
As you’ve probably noted, the above technique is not actually formatting our dimension. Instead, it creates a new measure and to format. This is the only way to conditionally format a dimension.
If you would just like to format the entire column (text or color), it’s a simple question of worksheet formatting. Here’s how to do it.
Text
Right click on the dimension in the view that you would like to format. Navigate to Format… > Default > Shading. Select the color you want.
Cells
Right click on the dimension in the view that you would like to format. Navigate to Format… > Default > Font. Select the color you want.
You will likely see that every 2 cells is colored. That’s because the setting for row banding is active.
To remove it, starting from the same format window, navigate to Shading (looks like the below image) > Pane > Row Banding. Select none for both colors, then minimize the banding size.
Color a Column Chart
There is one major use case for coloring a single column: when you have multiple columns in a view, and you only want to change the color of one. Stacked column charts also fall into this category.
Dimensions
Imagine we want to show a column chart of sales per month in the first quarter, i.e January, February, and March.
To color one month differently, it’s as easy as dragging the dimension you want to the color mark. In this case I’ve used months. It looks like this:
You could also choose to use a measure for coloring. However, simply dragging a measure to the color mark will produce a spectrum of color (because a measure is continuous). It would look like this:
To get clean-cut colors based on conditions, such as IF Measure > 10 THEN “Green” ELSE “Red” END, you’ll need to create a calculated field as shown in the above section.
Color a Bar Chart
Bar charts are just like column charts, except the bars are horizontal rather than vertical. The same methodology applies, so I won’t go into details here.
Color a Line Graph
The typical use case for coloring a line graph is when a date dimension is placed on the rows axis and two or more measures are placed on the column axis. In most cases I’ve encountered, the ideal is to cover each line differently.
In my example, I’ve placed the total income and count of sales on the Y axis and months on the row axis.
Dimensions
It’s easy to color lines. You simply place the “Measure Names” dimension on the color mark and your lines will take different colors of the measures in the view.
Be careful to select “All” in the marks window and not one of the measure mark windows. You can always make changes in them after, but start with “All.”
Measures
It is possible to color lines with a measure, but this will likely not give you what you’re looking for. Measures in the color mark result in a spectrum of colors like this, as in the column example:
There are very few cases in which a measure on the color mark is useful for visualizations, so you should prefer dimensions and custome dimensions (IF statements) where possible.
Color an Area Chart
Area charts functions exactly like lines. The only difference is that the space under the line is “filled in.” Use the same methodology from above. It looks like this:
Conclusion
If you found this article helpful, feel free to check out more free content at the AnalystAnswers.com homepage.