Color legend for custom ranges in Tableau

Said Tojiboev
4 min readApr 9, 2023

--

Tableau is a powerful data visualization tool that can help you create stunning maps with just a few clicks. By default, when you add a measure to the “Color” marks card in Tableau, it shows a sequential color legend from the lowest to the highest value of the measure.

However, sometimes you might want to create a custom color legend that indicates specific ranges of values for the measure. In this tutorial, we will show you how to create a custom color legend to show different interval ranges for a map in Tableau.

We will use the “Sales” measure and a US map of the Superstore data set for this example. The desired ranges for the Sales data are as follows:

  • Less than 20,000: “~20K”
  • 20,000 to 50,000: “20K~50K”
  • 50,000 to 100,000: “50K~100K”
  • 100,000 to 200,000: “100K~200K”
  • 200,000 to 300,000: “200K~300K”
  • 300,000 to 400,000: “300K~400K”
  • Greater than 400,000: “~400K”

Let’s get started!

Step 1: Connect to your data source and create a map

First, connect to your data source and drag the “Sales” measure to the “Color” marks card. Then, drag the “State” dimension to the “Detail” marks card and choose “Map” from the “Show Me” panel. You should see a US map with a sequential color legend for the Sales data. Instead of this sequential color legend, we create custom colors for ranges with a new calculated field

Step 2: Create a calculated field

Go to the “Analysis” menu and select “Create Calculated Field”. Name the calculated field “Sales Range” and use the following formula:

IF SUM([Sales]) < 20000 THEN “~20K”
ELSEIF SUM([Sales]) < 50000 THEN “20K~50K”
ELSEIF SUM([Sales]) < 100000 THEN “50K~100K”
ELSEIF SUM([Sales]) < 200000 THEN “100K~200K”
ELSEIF SUM([Sales]) < 300000 THEN “200K~300K”
ELSEIF SUM([Sales]) < 400000 THEN “300K~400K”
ELSE “~400K”
END

This formula groups Sales values into the desired ranges and assigns a text label to each range.

Step 3: Edit the color legend

Drag the “Sales Range” calculated field to the “Color” marks card. It automatically arranges colors for each range. If ranges are sorted alphabetically, they should be sorted from low to high numbers by holding and dragging.

Click the “Color” marks card, and select “Edit Colors”. In the “Edit Colors” dialog box, click on the “Palette” tab, and click any colors you want. Assign a color to each sales range by clicking the “Assign Palette” button. Click “OK” to close the “Edit Colors” dialog box and apply the new color palette to the map.

Step 5: Final touches

To make your map look more professional, you can add a title, change the font size and color, and adjust the margins. You can also add tooltips to show additional information about each state, such as the actual sales values or the percentage change from the previous period.

Once you have customized your map, you can save it and publish it to Tableau Server or continue it embed it on a webpage or blog. Your map will update automatically as new data is added to your data source.

Conclusion

Creating a custom color legend for a map in Tableau is a simple yet powerful way to communicate your data effectively. By grouping data into meaningful ranges and assigning a color to each range, you can highlight the patterns and trends in your data and make it easier for your audience to understand. With Tableau’s intuitive interface and robust features, you can create beautiful and insightful maps in no time.

--

--