X
Data Analytics | Data Visualization | Tableau

How to color measures by a dimensional field in Tableau

When working in Tableau, I find there are instances where we might want to color a text table based on a dimensional field, or maybe more specifically, a type of KPI. For example, lets say we have the table view below of Sales by Sub-category and Segment, and we want to color the numbers based on whether they are above, below, or in between certain thresholds.

We can create a calculation like the one below and simply put that on colors to achieve our result.

This may suffice for some of us, but what if I wanted to color the entire box rather than just the numbers? One might think to change the mark type from ‘Text’ to ‘Square’ and increase the size of the mark. However, you’ll soon realize that Tableau doesn’t give us what we expect. This post helps walk you through a couple of different ways to achieve the desired result below.

Option 1: Use a bar chart

Unfortunately, it isn’t enough to change the mark type to square because when using squares (or any other type of shape), those mark types aren’t self contained within their own cells. This is why when you increase the size of the square, the square traverses multiple cells and gives us some weird results. Given that information, using something like a bar chart works perfectly because bars within a chart are self contained to the specific combination of rows and columns.

Let’s go ahead and set up the view first:

Next, in the Marks Card drop down menu, change the mark type to ‘Bar’. You’ll actually notice when you make that change, small bars appear next to every value. If you are asking yourself, “why isn’t Tableau creating a bar for the size of the Sales value?”, keep in mind that SUM(Sales) is currently on ‘Text’. The ‘Bar’ mark is looking for a measure on Columns or Rows to calculate the size, and since there is no measure on Columns or Rows, the bar shows up as not really having a size, or rather, having a starting and ending position of zero.

Next, we’ll have to create an in-line calculation (or a regular calculation) of MIN(1) and add that to the columns shelf. Since we are putting this on the columns shelf, now Tableau is trying to size the bar to reach a value of 1 for each cell.

Now, with some formatting, we can right click the MIN(1) axis and make it a fixed range from 0 to 1.

From here, we can hide the MIN(1) header, increase the size of the bar, have the label align towards the middle, and make any other adjustments needed to get the right look and feel. At the very end, you’ll go ahead an place your dimension/KPI field on colors and BOOM, we have a text table with the cells colored in.

Option 2: Use a Gant Chart

This option follows the exact same steps as the previous option, with two exceptions. First, instead of choosing ‘Bar’ as the mark type from the Marks Card, you’ll choose ‘Gant Bar’. Second, you’ll have to move the dummy calculation of MIN(1) from the columns shelf to the ‘Size’ area on the Marks Card. In my honest opinion, this option is my favorite because it looks sleeker and formatting the borders of each cell is much easier.

Option 3: Using Dummy Dimension Fields

The final option is probably the easiest to implement. Let’s go back to our original view of Sales by Segment and Sub-Category. If we add our KPI to the color shelf, and change the mark to ‘Square’, we get a view like:

As we already discussed previously, if we try to increase the size of the shape, we start to see the squares overlap each other. A quick way to avoid the squares from overlapping each other is to double click on both the Columns and Rows shelf and type in two pairs of double or single quotes (these will serve as dummy dimension calculations). In doing so, Tableau will enclose the square to fit the unique combination of dimensions on Rows and Columns.

As you can see there are several options available to you to color measures by a dimensional field. Feel free to choose the one that works best for you. Tableau is a powerful platform that lets you explore and see your data in so many ways. We work with clients every day, helping them do more with their data. How can we help you? Drop us a line at [email protected].

Author

Related Posts

Oct 10 2023

Bet on Data: Navigating the Future of iGaming and Sports Betting

A look at the role key trends in customer experience, product innovation, and business growth have in shaping the sports betting and iGaming industry’s...
Abr 13 2023

The Databricks lakehouse TKOs the competition on TCO

Whether you look at hard dollars alone or add other factors, the Databricks lakehouse remains the most strategic investment.

Mar 20 2023

Introducing Gamehouse: A Lovelytics Game Analytics Brickbuilder Solution

Quickly stand up a 360-degree view of your game using Lovelytics’ game analytics Brickbuilder Solution

Ene 17 2023

Data lake + data warehouse = lakehouse: Modernize your data warehouse to a lakehouse

The View from the Lakehouse Blog Series PART 2 Over the past few years, the term “data lakehouse” has grown in popularity. Why?  Fundamentally, a data lakehouse...
Nov 30 2022

Why we bet our business on Databricks, and why you should too

The View from the Lakehouse Blog Series PART 1 Recently, Lovelytics held our first in-person all-hands meeting in more than a year. We gathered at our headquarters in...
Nov 23 2022

Three reasons why I’m thankful to be a part of the Lovelytics team

Most of us are inevitably going to be asked one of the most common questions this time of year: “What are you thankful for?”  Of course, I am grateful for my...
Oct 30 2022

Alteryx Tool Tip: Don’t Fear the Blob

Using the Blob Tools to Output Data into Formatted Excel Templates While “the Blob” might sound like a cheesy horror movie or an unidentified substance you scrape off...
Oct 22 2022

Web Scraping With the Modern Data Stack

I’ve always found web scraping interesting, there’s a massive trove of data available to us in a wide array of formats- it presents the perfect ‘big data’ problem, how...
Oct 12 2022

Alteryx Tool Tip: The Multi-Row Tool

Have you ever added a formula tool to your Alteryx workflow and suddenly realized that your IF/THEN logic is starting to look more like a book and less like a logical...
Oct 10 2022

Performing Ad-Hoc Analysis and developing agile dashboards in Databricks SQL

Synopsis: This article is a 101 level introduction to Databricks SQL, and will walk you through the steps to build simple visualizations directly within a Lakehouse...