In this post I'm going to show you how to use Shape Maps in Power BI, which are currently a preview feature.
Typically, Shape Maps are used to illustrate the variation of a variable across a geographic area like a country or state.
But you can also create custom shape maps for things like buildings, seating arrangements, or custom geographic regions.
I'll explain how to assign colors using color saturation, and how not to use colors, plus I'll show you a trick to plot categorical data and assign specific colors to the categories.
Watch the Video
Download PBIX Desktop File
Enter your email address below to download the sample files used in this post.
Getting Started With Shape Maps
Shape Maps are a Preview Feature in Power BI Desktop and are not enabled by default.
To turn on Shape Maps, go to the File menu -> Options and settings -> Options
Click on Preview features and check the box beside Shape map visual.
Click OK, then restart PBI Desktop.
Once restarted you should have Shape Map available in the visuals.
Adding a Shape Map
The first thing I'm going to visualize is the population distribution in mainland Australia by state and territory.
NOTE: Mainland Australia comprises six states and 3 internal territories, although the Jervis Bay territory is counted as part of the ACT for administration purposes. So in practice you'll see six states and two territories on maps. More info.
Here's my data, from 2020, sourced from WikiPedia.
I'm using the state/territory abbreviations as well as the ISO standard codes. I'll talk more about these in a bit.
Click on the Shape Map icon in the Visuals area to add a map. You'll see a placeholder appear on the canvas.
Add Population to the Color Saturation well and State/Territory to Location - and my map shows the USA.
What's going on?
First, notice that the map of the USA has some color applied. That's because WA is the abbreviation for both Washington state in the USA, and Western Australia.
Because the default map is displaying USA, PBI thinks the data I've given it is for the USA so it does it's best to plot that data.
However if I change Location to contain the ISO codes for the Australian states and territories PBI now knows my data is for Australia and doesn't plot it in the USA map.
So if you are using a map with places that have identical names or abbreviations, you must use a unique identifier for each location.
So I change the map to Australia
and everything is plotted correctly.
I can actually remove the ISO states and just use the State/Territory (which are abbreviations) or the full State/Territory Name and I'll get the same results.
This is of course because there aren't any states or territories with the same abbreviations or name, and because the map keys understand both the abbreviations and full state and territory names.
Map Keys
If you look here at the map keys
You can see the unique identifiers the map recognises. You can use any of these to refer to the areas in the map, which is why I can use both full state/territory names, or their abbreviations.
Add A Table
There aren't any labels for the map so it can help to add a table. In practice the map won't generally be on its own. It'll be used in conjunction with other visuals which will give you that missing information like state/territory names.
To make the table more helpful I can add conditional formatting for both columns to match the map colors.
To do this, click on the table, then in the Values, click the down arrow beside State/Territory Name -> Conditional Formatting -> Background Color.
The settings are almost the defaults.
- Format by : Color scale
- Apply to : Values only
- Based on field : Select Population here and it will display as Sum of Population (the default summarization)
- Summarization : Sum
- Default formatting : As zero
- Minimum : Lowest value
- Maximum : Highest value
Repeat for the Population column.
Color for Minimum and Maximum Values
If I select a state or territory from the table, like Tasmania, it's highlighted in the map - but notice that it's color has changed from the color it has when nothing is selected.
This is because I've used the default settings for the Max and Min values in the Data Colors.
I haven't specified anything for either so PBI uses the smallest and largest values currently selected (or all values if nothing's selected).
So if I select Tasmania it changes from pale blue to deep blue because with only one state selected, that state is given the color for the largest value, the deep blue.
To prevent this behaviour and force each state/territory to stay the same color regardless of selections, I can manually enter minimum and maximum values for the map colors.
These values are still the minimum and maximum populations, but these numbers will now always be used to assign a color in the range given he specific max and min values, regardless of active selections in other visuals.
Now if I click Tasmania in the table, it stays the same color in the map.
Manually Choosing Map Colors
You can choose your own map colors but choosing dissimilar colors leads to confusion - I don't know what the map is telling me now.
Likewise, turning Diverging colors on for this map is not helpful.
Using the Legend
Adding State/Territory to the Legend colors each one individually, but again you lose the meaning of the message here. The colors no longer indicate the population distribution.
If the purpose it to educate the viewer on the location and names (or abbreviations) of the states/territories you can use this map to do this. But if you had a lot of items in the Legend it will look very messy.
Categorical Data
OK let's look at another use for shape maps. Rather than seeing the distribution of a value like population, I want to see which political parties have been elected to which state/territory.
At the moment in Australia we only have 2 parties in power : Labor and the Liberals. Here you can see which party is in control of which state or territory.
It's not obvious how to create a shape map based on text values, but it's super easy.
Start by inserting the Shape Map visual, then insert the State/Territory Name in the Location field, the Elected Party in the Legend field and the Elected Party again in the Color Saturation field. Power BI will count the Elected Party, which is fine:
You can then apply the colors you want in the Data Colors settings:
Where To Get Extra Maps
You may have noticed there aren't many default maps available
Shape Maps in PBI are a type of map known as TOPO-JSON. You can search online for sites that provide them but I've found a good collection on David Eldersveld's GitHub repository.
Robert Green
I have been sent some location data in the form of a .kml file which is displayed in Google Earth. How can I add that data to an existing shape map in Power BI?
Mynda Treacy
Hi Robert,
I’m not familiar with the .kml file type, sorry. Shape maps can only plot county, state and country level of data. I suspect your location data is more precise than that and therefore not suitable for shape maps..
Mynda
Robert
Thank you, Mynda. That makes sense!!
On the maps of Australia above, that Philip has been demonstrating, is it possible to also display the data values on the shape map rather than colouring as a ‘heat’ map?
ie. add the actual populations to the various states directly on the map visual?
Mynda Treacy
The best you can do with these maps is have the value appear as a tooltip on hover.