Mapping and filtering data with custom polygon maps

acheung's picture
By Andrew Cheung- August 18, 2014

Tableau has many great built-in geographic areas available for mapping data. And if the geographic areas you’re interested in using aren’t available, Tableau can draw maps of any area type using custom shapes.

Thanks to the great members of the Tableau community, many custom shape maps are already available as premade Tableau Data Extracts. Here are a few examples of resources that come up with a simple web search:

Using the premade TDEs means you’ll be blending your data to map it, and in this post we’re going to cover some of the nuances of how to make that work out best.

One common task when working with a map is filtering with a map using your data source. To accomplish this we’ll be using a technique that is not exactly like the native filtering features baked into Tableau.

Instead we’ll use parameter controls to act as the filter selectors for your fields of choice, and build calculated fields to drive the filtering process.

Our exercise toolkit

First download this zip file that contains all the files we’ll need to run through this exercise:

Blending our data sources

To get started we’ll connect to the TDE that contains our map of interest and the dataset we’d like to display on this map. To reduce confusion we’ll refer to these data sources as the map source and the data source from now on.

Once connected to both sources, the next step is to make a map. Craig has an excellent video that explains this process:

Here’s what your map ought to look like before moving on (it may be a different color):

The next step is to blend our map source and data source on a common field, usually a geographic location field. It’s important that the location names in each source match, so check your raw data to see that there aren’t any differences. Often times data sets will have the same location fields in spirit, but may vary in capitalization or append “city” or some other type identifier to the name.

In our case, location names are stored in the Area Names field for the map source, and as F13 - District in the data source. Because they differ in capitalization, we’re going to create calculated field copies of each that apply the lower() function:

Then we can edit the relationship between the map and data sources:

Make sure your relationship is active, signified by an unbroken chain symbol on the fields we’re blending on:

If it looks like this,

just click the broken chain symbol to activate the blend.

Now to check if our blend worked correctly, we’ll drag the F2 - Price field color on the Marks card, and we should see our map color coded by SUM(F2 - Price):

Filtering across our blended sources

Once we’ve blended our sources successfully, we’ll need to create a parameter control for each filter that we would create, as well as a corresponding calculated field in our data source to make everything work.

In our sample data source, one of the fields describing each property transaction row indicates whether the property transacted was a new construction or previously established building.

Let’s say we wanted to filter the map to show only new or old properties. First we create a parameter named New or old:

Then we create a calculated field in the data source, we’ll name this one New or old filter:

if [New or old] = [F6 - Established/old (N) / Newly built (Y)] then "Show"
else "hide" end

This calculated field is serving as a toggle; we could put anything in place of “Show” or “hide” but it’s best to keep it intuitive in case you need to rework the filter at a later date or someone else has to work with it.

Next we drag our New or old filter calculated field to the filters shelf, and check “Show” in its dialogue box:

The map should change once you confirm this filter. Then we show the parameter control in order to toggle the display between new and old properties:

Now when we change the parameter, the map is filtered accordingly. Et voila!

Using the same example, if we wanted to filter the map based on the year when transactions occurred, we would create an additional parameter named Years:

And then create another corresponding calculated field:

if [Years] = datepart('year',[F3 - Date of Transfer]) then "Show"
else "hide" end

In this case, our year information is contained within a date type field, so the datepart() function selects only the year to test if it matches against the parameter.

Then we repeat the filter setup process and show the parameter control as above, and now we can filter based on the year as well:


I've managed to get this far and it works pretty well. However, what I need to do is use selections on the map to filter different worksheets from a different data source (with common fieds, of course).

For example, I may have a map with all the constituencies in the UK. I also have table based on another worksheet that has ward level results data for each of these constituencies. Is there a way to filter the contents of the ward level results data by just clicking on the constituency in the map?

Not sure how to get around this problem. I want to calculate the year over year growth (change) while mapping the data but when I go to the Quick Table Calculation Link it is not available.

The problem does not exist when the data is not being mapped.

Thank you for the post.

In the very first image, (the all blue one), the boundaries are visible. But when you filter, only the selected polygons are visible. The filtered out polygons don't show the (say county borders) boundaries and only the country border is visible. This does not look good. It may lead users to loose the context. Any ways to over come this ? or I didn't fully understand this ? Pls explain.

Moreover, why parameter control is needed for filtering ?