In this series, we will explore different types of calculations involving calculating distance. From a simple iteration to geographic clustering, we will take your data as far as it can go with Tableau.
In the last blog, we looked at comparing all locations against a single, static point.
Now, we can build on this and account for a selection of points in our distance calculation by using a parameter. This will enhance the interactivity of our viz and allow selection of a comparison city from a list of cities:
Here, I use a string parameter to list out my five distribution centers; if you need a performance boost, try using an integer parameter and setting the Display As to your city names. Then I create two calculated fields, both tied to the one parameter, separately referencing the latitude and longitude of the five parameter members. I then include these two calculated fields in my distance calculation:
And if you want to copypasta:
3959 * ACOS ( SIN(RADIANS([lat])) * SIN(RADIANS([lat parameter calc])) + COS(RADIANS([lat])) * COS(RADIANS(35.4720)) * COS(RADIANS([long parameter calc]) - RADIANS([long])) )
3959 is half of the Earth’s diameter in miles. If you are using kilometers, this needs to be 6371 km.
The next post in this series will take this a step further and focus on going completely dynamic with table calculations.