In recent years, Tableau has added a bunch of really cool mapping features that have allowed users to take their geospatial analytics in Tableau to the next level. In this blog post, I use some of those cool new features such as buffer and distance calculations and combine them with parameter actions to complete an interactive geospatial analysis.
The dashboard that I will use as an example is similar to a project we completed for a client that wanted to see how many stores that carried their product were located inside a certain radius in order to understand the impact of the pandemic on their business in certain locales.
The dashboard below allows users to click on any city on the map and see what % of cities on the map exist within a certain mile radius of that city. You can also see the aggregate profit margin for cities within that radius as well as what percentage of all profits come from with the radius. You can manually adjust the radius in the top right of the dashboard.
To create the map that is shown in this dashboard we take advantage of the map layers feature released in Tableau 2020.4. You can read more about them here.
Before we start creating the map, I will be referencing the Profit Margin field a lot, so here is the calculation for that field. All we are wanting to do is to see what percentage of Sales that we are turning into Profit.
//Profit Margin = SUM([Profit])/SUM([Sales])
Now let’s get making this map!
- States– for this map layer, I dragged State to detail and colored each of the states by their Profit Margin.
- Cities – to show the cities I added a map layer by dragging the City field to the top left of the existing map where it says “Add a Marks Layer”. I then made sure to bring in the State level of detail as well to make sure every city showed up. Sometimes there are cities that exist in multiple states, so make sure you’re showing every city/state combination. I colored the cities by the Profit Margin field and then added color based upon the absolute value of the Profit Margin.
Now that we have all of our points plotted out, let’s create the Buffer calculation to give us our last map layer.
The Buffer calculation created a radius, or “buffer”, around a certain point on a map that you can define within the syntax. Below is the syntax for Buffer. The first part dictates what location you’ll define as the center, then the distance around the point, and then what unit of measurement will be used.
//Buffer Syntax = Buffer(Spatial Point, distance, "units")
To create the point that we want to use as the centroid, we use the Makepoint function. This function just takes a Latitude and Longitude and makes a point on the map. You can see the calculation below.
//Buffer = BUFFER( MAKEPOINT( SUM([Location Lat]), SUM([Location Long])), [Radius],"mi" )
In order to get the interactivity we want, I first created three parameters; [Location Lat], [Location Long], and [Radius]. I wanted these to be parameters because I want the user to have the ability to change each of these in the dashboard to their liking. The Location Lat and Location Long fields will change because upon what cities we click on. The Radius field will be an input parameter that will allow users to change the radius distance.
Now that we’ve created the last map layer field, we can drag this field to the to left of the map and add it to the map. Now you should have all of the map layers on the map to recreate our dashboard as seen below.
Now that we have the map layers we want, we have to add some parameter actions to get the Location Lat and Location Long fields to change when we click on a city. This parameter action will change the MAKEPOINT() field within the Buffer calculation and change where the radius is located. You can see how we’ve set up the parameter action below.
Lastly, we want these parameters to change the metrics that are available at the top of the dashboard. These metrics give indicators about the concentration of profit and profit margin that are found within the chosen radius. Below you can find both the supporting calculations and calculations for metrics shown on the dashboard.
//Average Lat/Long = MAKEPOINT([Latitude],[Longitude])
//Lat/Long Make Point = MAKEPOINT([Latitude],[Longitude])
//Distance from Point = DISTANCE([Average Lat/Long],[Lat/Long Make Point],"mi")
//Location Within Radius = [Distance from Point]<=[Radius]
//% of Cities Within Radius = COUNTD(IF [Location Within Radius] THEN [City State] END)/COUNTD([City State])
//% of Profit Within Radius = SUM(IF [Location Within Radius] THEN [Profit] END)/SUM([Profit])
//% Profit Margin Within Radius = SUM(IF [Location Within Radius] THEN [Profit] END) / SUM(IF [Location Within Radius] THEN [Sales] END)
If you are not able to follow these calculations, you can download the workbook here from Tableau Public and check out the calculations in more details.
This dashboard was fun to create for our client because it helped them interact with their data and find out more about their operations. Hopefully, this blog has shown you how to recreate the geospatial example that I’ve created as well as given you the inspiration to come up with your own ideas for analysis.
Need more help making your Tableau dashboards a work of art? Our knowledgeable team of Tableau experts is here to help!