Learn how to apply conditional formatting in Tableau

Posted on Mar 31, 2022

See how you apply a conditional format to your table using Tableau


Tableau focuses on visualizing your data and communicating information. So, it doesn’t provide a conditional formatting control that can be applied across a column.

In Tableau, you need to use a combination of marks and calculated fields to apply conditional formatting rules to the data in your sheet.

The example below shows how you can apply conditional formatting in Tableau:

In the above example, the conditional color of the cells is applied for the Total Sales mark.

This tutorial will help you learn how to apply conditional formatting in Tableau as shown above.

First, you need to download the dataset used for this tutorial here:

SalesData.csv

Once downloaded, you can load the dataset into Tableau as a Text File.

Here are the steps to apply conditional formatting for the Total Sales field:

Drag the City field to the Columns shelf and the Item field to the Rows shelf.

Add the Total Sales field as Color and Label marks to the sheet.

Click on the Color mark and select Edit Colors… then change the palette to Red-Green-Gold Diverging.

Check the Stepped Color and use 3 steps to create three different colors:

Once done, click OK and change the mark type from Automatic to Bar.

You should see the following table in your worksheet:

The last thing you need to do is to add a field as a Size mark that can be used to fill the cells with a background color.

The easiest way to do it is to create a calculated field with a single value and add it as the Size mark.

Create a calculated field named Cell with 0 as its value, then add it to the sheet as a Size mark.

Click on the Size button on the Marks pane and maximize the size to fill the table cells.

You should see the following table in your sheet:

And that’s how you apply conditional formatting when creating a table using Tableau.

If you want to customize the format further, you can also create a calculated field as the Color mark.

First, create a calculated field that will group your measure field values into labels.

For example, the Total Sales field can be grouped based on the amount for each row:

IF SUM([Total Sales]) > 3500 THEN "Great"
ELSEIF SUM([Total Sales]) > 1500 THEN "Good"
ELSE "Low"
END

Save the above formula as a calculated field named Total Sales KPI, then add the field as the Color mark to the sheet.

Right-click the generated Colors pane, then edit the colors and sort the labels to match your requirements:

And that’s how you can apply conditional formatting in Tableau.

You can view and download the workbook for this tutorial here:

Tableau Conditional Formatting

You can use the same principles for any other dataset you have for your project:

  • The Colors mark uses the field you want to measure
  • The Size mark uses a single value field to fill each cell with color
  • Use the Bar type mark to apply the colors correctly

I hope this guide helps you learn how to apply conditional formatting in Tableau. 🙏

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.