KNOWLEDGE BASE

Creating a Filled Map with Custom Groups

Product(s): Tableau Desktop
Version(s): 8.1, 8.0, 7.0

Article Note: This article is no longer actively maintained by Tableau. We continue to make it available because the information is still valuable, but some steps may vary due to product changes.

This article describes how to create a map that uses custom groups based on geographic regions, where each group is shown in a different color. The color is based on an aggregate measure. This type of view helps you to see at a glance the results of each group for that measure. For example, using the Profit field, as in the following image, you can quickly see which groups are more profitable than others.

To follow along with the steps to create this view, download the attached packaged workbook, Filled Map Custom Groups.twbx.

The workbook uses the Superstore sample data set, along with a custom group called State (group), in which the 50 US states are grouped into four regions. It also uses a calculated field to color the custom group based on profit.

Create a calculated field to aggregate a measure across a specified area

In the map view, you will use this calculation to find the sum of profits for all of the states within each custom group.

Step 1

Open the Filled Map Custom Groups.twbx workbook you downloaded, and select AnalysisCreate Calculated Field

Step 2

In the Calculated Field dialog box, complete the following steps.

1. For Name, type Group Profit.
2. In the Formula box, build the following formula:

`WINDOW_SUM(SUM([Profit]))`

3. Confirm that the formula is valid, and then click OK.

The new calculation is added to the Measures pane.

You can create a new calculated field for each measure you want to use. You can also modify the calculation for a different aggregation, for example, to calculate the average.

Create the map view

Step 1

In the Filled Map Custom Groups.twbx workbook, create a new worksheet.

Step 2

In the Dimensions pane, complete these steps:

• Double-click State.
• Drag State (Group) to Detail on the Marks card.
• Drag State to Detail.

Tip: You can see how the State (Group) dimension is set up by right-clicking it in the Dimensions pane, and selecting Edit Group.

Step 3

From the Measures pane, drag Group Profit to Color on the Marks card.

This colors states individually.

Step 4

On the Marks card, click the down arrow on Group Profit, and then select Edit Table Calculation.

Step 5

In the Table Calculation dialog box, for Compute Using, select Advanced, and in the Advanced dialog box, complete the following steps:

1. Under Available Fields, select State (Group) and click the right arrow to move it to the Compute Using section.
2. Do the same with State, and then click OK.

Note: Make sure to follow this sequence. If you move the items in the opposite order—that is, State first and then State (Group)—the view will not work properly for this example.

Step 6

In the Table Calculation dialog box, for Restarting Every, select State (Group).

These changes tell Tableau to aggregate Profit up to the level of the custom groups. Now the map is colored by the groups. To see a region’s profit number, hover the pointer over a state.

Step 7 (optional)

If you do not want to see the individual state names in the tooltip (along with the group name), on the Marks card, open the drop-down menu on State, and select Include in Tooltip to clear the check mark.

Allow users to select the measure they want to use to color the map

The attached sample workbook also contains a more sophisticated example, which shows you how to let users choose the measure on which they want to base the map coloring.

To build this view, you create a new calculated field for selecting the measure. In this field, you will include a new parameter to specify which measures you want to allow users to select.

Step 1

Select Analysis > Create Calculated Field.

Step 2

In the Calculated Field dialog box, complete the following steps.

1. For Name, type Measure Selector.
2. Above the list of parameters, click Create to create a new parameter.
3. In the Create Parameter dialog box, set the following:
• Name: Select a Measure
• Data type: String
• Allowable values: List
• Value column: Enter three values of Sales, Profit, and Shipping Cost.

You can type a value and press Enter to auto-fill the Display As column and move to the next row.

4. Click OK, and then in the Formula box, build the following formula:

```CASE [Select a Measure] WHEN "Sales" THEN WINDOW_SUM(SUM([Sales])) WHEN "Profit" THEN WINDOW_SUM(SUM([Profit])) WHEN "Shipping Cost" THEN WINDOW_SUM(SUM([Shipping Cost])) END```

5. Confirm that the formula is valid, and then click OK.

The first line of the calculation uses your new parameter to indicate that Tableau should follow the subsequent lines of the formula when a user changes the setting. The subsequent lines indicate how to control the view (how to color the map in this case) based on which value the user selects.

Incorporate the new field into the view

Step 1

From the Measures pane, drag Measure Selector to Color.

Step 2

On the Measure Selector field on the Marks card, open the drop-down menu, and select Edit Table Calculation.

In the Table Calculation dialog box, apply the same changes to the Measure Selector field as you did in steps 5–6 in the Create the map view section earlier in this article.

Step 3

In the Parameters pane, on the Select a Measure drop-down menu, select Show Parameter Control.

This exposes the parameter to users.

Step 4

Select WorksheetTooltip, and in the tooltip text, do the following tasks:

• Select the text Measure Selector.
• On the Insert menu toward the upper-right of that dialog box, select Parameters.Select a Measure.

Now when a user hovers over the map, the value appears with the measure that is being used to color the map. In this case, the Sales, Profit, or Shipping Cost for the group that appears in State (group).

Alternate Search Terms:custom regions