Tableau Colour a Heatmap with a Dimension


In Tableau, adding colour to a table using a measure is very simple. However, adding colour to a Tableau table using a dimension is more complicated.

A heatmap (or highlight table) is basically a table with colour. Usually the colour is from a measure (green pill) – for example, colouring by sales high to low, or something similar.

However, there are times to colour a heatmap by a dimension (a blue pill). For example, perhaps there’s a crosstab table of sub-category and month, which should colour each sub-category by its category.

If building a dimension based heatmap using the Square mark type, the same way as using a measure to colour, you’re likely to experience the colour coming out of the cell.

The colour coming out of the cell is annoying, but simple to fix with a slight change in technique.

How to colour a Heatmap with a Dimension

To create a heatmap/highlight table using a dimension to colour, start by laying out the table.

In this example, using Sample Superstore, show Sales by Sub-category and Segment. Then colour each cell by the Category.

Put Segment to Columns, Sub-category to Rows and Sum of Sales to Text.

A simple crosstab table in Tableau
Simple crosstab table in Tableau

Next, change the mark type to Gantt Bar. Then drag Category to the Colour shelf.

A simple crosstab table in Tableau with a gantt bar mark type
Add the dimension to Colour and Mark type to Gantt Bar

Observe the colour being a simple line. To make the heatmap, that colour should cover the entire cell.

To colour the entire cell, create a simple calculation with the value 1. (Very useful calculation to have in all workbooks; it works well as a placeholder for complex tables, and also to count the number of records.)

tableau crosstab showing a gantt bar like a bar chart
Change the aggregation of 1 to Min so it always has the value 1

Put this on the Size shelf and change the aggregation to Min. Therefore, it will always return the value 1. Summing would inadvertently sum the number of records, producing the small bar chart affect in the image above.

Finally, click on the Size box and drag the size out to fill the space.

a tableau heatmap stretching the size to fill the cell
Drag the Size to the far right

And that’s it, a simple way to create a heatmap in Tableau using a dimension to colour!

Tableau heatmap in Tableau with colour from a dimension
The end product – a Tableau heatmap with colour by a dimension

If curious, change the mark type to Square and remove the MIN(1) from the Size shelf. Exactly like a standard measure-coloured heatmap. Try and get the colour to cleanly fill the cell!

2 thoughts on “Tableau Colour a Heatmap with a Dimension”

Leave a Comment