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:
- sample property transaction dataset.xlsx - our data source, a trimmed version of property transaction data from the UK Land Registry
- Counties,+Unitary+Authorities+&+Local+Authorities+v8.tde - our map source, the UK polygon map from Tableau Zen Master Craig Bloodworth of The Information Lab
- sampleworkbook.twbx - the completed version of what we’ll be doing
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: