How to Calculate Distance in Tableau

Cody Schneider8 min read

Calculating the distance between two points on a map is a powerful feature for geographic analysis, yet it's often seen as a complicated task. It doesn't have to be. Tableau provides a straightforward way to measure the distance between sets of coordinates, enabling you to analyze supply chains, plan sales territories, or understand customer behavior. This article will guide you through the process step-by-step, showing you exactly how to use Tableau's spatial functions to calculate distance.

Prerequisites: Getting Your Data Ready

Before you can calculate distance in Tableau, your data needs to be structured in a specific way. The fundamental requirement is having sets of latitude and longitude coordinates. For most distance calculations, you'll need two pairs of coordinates in each row of your dataset:

  • An origin point (e.g., a warehouse, a distribution center, a store)
  • A destination point (e.g., a customer's address, a delivery location, another store)

Your data source, whether it's an Excel file, a Google Sheet, or a database table, should look something like this:

Most importantly, make sure Tableau recognizes these fields as numerical data types (e.g., Number (decimal)). Although it's good practice to assign geographic roles like "Latitude" and "Longitude" to these fields, the distance functions will work as long as a valid set of coordinates is provided.

Understanding Tableau's Spatial Functions

Tableau's ability to handle distance calculations relies on a few key spatial functions. These functions transform your raw coordinate numbers into spatial objects that Tableau can use for geographic analysis.

The Core Functions for Distance Calculation

  • MAKEPOINT(latitude, longitude): This is the foundational function. It takes two numerical fields - a latitude and a longitude - and converts them into a single spatial point object. You cannot calculate distance without first creating these points.
  • DISTANCE(point1, point2, 'units'): Once you have two spatial points, this function calculates the straight-line distance (or "as the crow flies") between them. It’s simple yet powerful.
  • MAKELINE(point1, point2): While not required for the calculation itself, this function is incredibly useful for visualization. It takes two points and draws a line between them on a map, which is perfect for visualizing routes or connections.

The third argument in the DISTANCE function, units, is a string that specifies the unit of measurement. Tableau accepts the following unit options: 'm' (meters), 'km' (kilometers), 'mi' (miles), and 'ft' (feet). Always specify the unit to avoid ambiguity in your reports.

Method 1: Calculating Distance Between Two Sets of Points

This is the most common use case, where you have columns for both an origin location and a destination location in your dataset. Let's walk through building the calculation and visualizing it.

Step 1: Create Your Geographic Points using MAKEPOINT

First, you need to convert your origin and destination latitude/longitude pairs into spatial point objects Tableau understands. You'll do this by creating two separate calculated fields.

  1. Open your Tableau workbook and go to the worksheet where you want to build the map.
  2. In the Data pane, click the dropdown arrow at the top and select Create Calculated Field.
  3. Name this first calculation "Origin Point". In the formula box, enter the following:

MAKEPOINT([Warehouse_Latitude], [Warehouse_Longitude])

Click OK to save it. You'll notice this new field has a globe icon next to it, indicating it's a spatial data type.

  1. Now, create a second calculated field. Name this one "Destination Point". The formula will be similar, using your destination coordinates:

MAKEPOINT([Customer_Latitude], [Customer_Longitude])

Click OK again. You now have two dedicated spatial fields that represent the specific geographic points for each row in your data.

Step 2: Calculate the Distance with the DISTANCE Function

With your points created, you can now calculate the distance between them. This requires one more calculated field.

  1. Create another new calculated field and name it "Shipping Distance" or something similar.
  2. In the formula box, use the DISTANCE function to reference the two point fields you just made:

DISTANCE([Origin Point], [Destination Point], 'miles')

Remember to change 'miles' to 'km' or your desired unit if needed. Click OK. This field will now contain the calculated distance for every row.

Step 3: Visualize the Calculation on a Map

Seeing numbers in a table is one thing, seeing the distances on a map is far more impactful. Here's how to create the visual:

  1. In the Data pane, find the Tableau-generated "Latitude (generated)" and "Longitude (generated)" fields. Drag Latitude to the Rows shelf and Longitude to the Columns shelf. Tableau will automatically switch to a map view.
  2. Drag your "Origin Point" calculated field onto the map. Dots will appear representing these locations.
  3. Drag your "Destination Point" calculated field onto the map layer area. This creates a dual-axis map with two sets of points. You can now format each layer independently (e.g., make warehouses larger circles and customers smaller circles).
  4. Drag your "Shipping Distance" calculated field onto the Color tile on the Marks card. Instantly, the color of your points will change based on how far away they are, giving you a quick visual reference for short vs. long distances.
  5. Bonus Visualization - Draw the Lines: To make the connection explicit, create one more calculated field called "Delivery Path" using the MAKELINE function:

MAKELINE([Origin Point], [Destination Point])

Drag this new "Delivery Path" field onto your map visualization. Tableau will draw a straight line from each origin to its corresponding destination, clearly illustrating the distances you've just calculated.

Method 2: Calculating Distance from a Single, Fixed Point

Sometimes you don't have two dynamic points. Instead, you want to calculate how far all your customers, stores, or employees are from a single, fixed location, like a head office or a central distribution center. The process is similar but even easier.

Step 1: Set Your Fixed Point

The key difference is that instead of a second point coming from your data, you'll create it directly in the calculation. Let's say your main office is in Chicago (Latitude: 41.8781, Longitude: -87.6298).

Create a calculated field and name it "Distance from HQ". Use this formula:

`DISTANCE( // The first point is dynamic, from your data source MAKEPOINT([Customer_Latitude], [Customer_Longitude]),

// The second point is fixed, directly entered here
MAKEPOINT(41.8781, -87.6298),

// The unit of measurement
'miles'

)`

This single formula references the latitude and longitude from each row of your data and measures its distance to that one specific spot in Chicago. You don't need to create separate point fields beforehand.

Step 2: Using Parameters for a Dynamic "Fixed" Point

Want to make your dashboard more interactive? Instead of hard-coding the latitude and longitude of your fixed point, you can use parameters. This lets you or your end-users change the central point on the fly to see how distances change relative to different locations.

  1. Create a new parameter named "HQ Latitude," set the data type to Float, and give it a current value (e.g., 41.8781).
  2. Create another parameter named "HQ Longitude," set it to Float, and set its current value (e.g., -87.6298).
  3. Now, adjust your calculated field to use these parameters instead of the hard-coded numbers:

DISTANCE( MAKEPOINT([Customer_Latitude], [Customer_Longitude]), MAKEPOINT([HQ Latitude], [HQ Longitude]), 'miles' )

Now, by right-clicking the parameters and selecting "Show Parameter," users can type in new coordinates to update the distance calculations across the entire dashboard instantly.

Troubleshooting Common Issues

If your distance calculations aren't working, here are a few common culprits to check:

  • Null or Non-Numeric Data: The MAKEPOINT function will return null if either the latitude or longitude it receives is null, blank, or not a number. The DISTANCE function will, in turn, return null. Check your source data for any missing coordinates or text values in those columns.
  • Incorrect Signs for Longitude: A very common mistake is forgetting the negative sign for longitudes in the Western Hemisphere (e.g., all of the Americas). Using 87.6298 instead of -87.6298 will place your point on the opposite side of the planet and result in huge, inaccurate distance figures.
  • Argument Order: Remember that the standard is always MAKEPOINT(Latitude, Longitude). Mismatching the order will place your point in the wrong location.

Final Thoughts

By using Tableau's MAKEPOINT and DISTANCE functions, you can change raw coordinates from simple map dots into powerful business insights. This extra layer of context helps you understand supply chain efficiency, customer density, and sales potential in a way that tables of numbers simply can't match.

Building dashboards like this, with multiple calculated fields, dual-axis maps, and spatial logic, requires practice and can often be a repetitive, time-consuming task. At Graphed, we created a tool that automates this entire process. Instead of manually clicking, dragging, and writing formulas, you can connect your data sources and simply ask in plain English: "Show me a line map of all orders from warehouse to customer, colored by shipping distance." Our AI handles the data connections and builds a live, interactive visualization instantly, freeing you to focus on strategy instead of report-building.

Related Articles

How to Connect Facebook to Google Data Studio: The Complete Guide for 2026

Connecting Facebook Ads to Google Data Studio (now called Looker Studio) has become essential for digital marketers who want to create comprehensive, visually appealing reports that go beyond the basic analytics provided by Facebook's native Ads Manager. If you're struggling with fragmented reporting across multiple platforms or spending too much time manually exporting data, this guide will show you exactly how to streamline your Facebook advertising analytics.

Appsflyer vs Mixpanel​: Complete 2026 Comparison Guide

The difference between AppsFlyer and Mixpanel isn't just about features—it's about understanding two fundamentally different approaches to data that can make or break your growth strategy. One tracks how users find you, the other reveals what they do once they arrive. Most companies need insights from both worlds, but knowing where to start can save you months of implementation headaches and thousands in wasted budget.