Back to HERE in Google Sheets
SheetXAI logo
HERE logo
HERE · Google Sheets Guide

Build a Distance Matrix from Depots and Customers in Google Sheets

2026-05-13
4 min read
See the Excel version →

The Scenario

You are a logistics planner. The route optimization model runs every Monday at 7 AM and it needs a full distance matrix:5 warehouse origins against 40 customer delivery destinations. That is 200 origin-to-destination travel times.

Your sheet has the depots in the "Depots" tab (lat/lng in columns A and B) and customers in the "Customers" tab (lat/lng in columns A and B). The "Distance Matrix" tab is empty and waiting.

The bad version of Monday morning:

  • You open the routing model and realize the input file format changed last week
  • You try to update the script someone wrote six months ago
  • The script calls HERE's routing API 200 times in a loop, one pair at a time, and it hits a rate limit after 80 calls
  • You restart, it errors on row 43
  • The model does not run. The Monday morning logistics call is in 90 minutes.

The fast version is one prompt.

The Easy Way: One Prompt in SheetXAI

SheetXAI is an AI agent inside your spreadsheet that reads both tabs and calls HERE Matrix Routing for all 200 pairs in one batch, writing results into the Distance Matrix tab.

Open the SheetXAI sidebar and type:

Use HERE Matrix Routing to compute drive times between all 5 origins in the Depots tab (lat/lng in columns A and B) and all 40 destinations in the Customers tab (lat/lng in columns A and B). Write the results as a 5×40 table in the Distance Matrix tab, with origin depot names as row headers and customer names as column headers.

SheetXAI reads both tabs, calls HERE Matrix Routing for the full set of pairs, and writes the completed distance matrix into the "Distance Matrix" tab with headers. The routing model gets its input on time.

What You Get

A complete, labeled distance matrix in the "Distance Matrix" tab:

  • 5 rows — one per depot origin
  • 40 columns — one per customer destination
  • Depot names as row headers and customer names as column headers, so the matrix is readable without cross-referencing

The routing model reads this tab directly. No reformatting, no transposing, no script.

Need distance in kilometers instead of (or alongside) minutes? Ask SheetXAI to add a second matrix in the same tab below the first.

What If the Data Is Not Quite Ready

Matrix routing jobs are sensitive to data quality and format. SheetXAI handles the common issues in the same prompt.

When depot and customer names have inconsistent formatting

Your "Depots" tab uses uppercase names ("WAREHOUSE NORTH") and your "Customers" tab uses title case ("Acme Logistics"). The matrix headers will be inconsistent.

Normalize all depot names in the Depots tab to title case in column C and all customer names in the Customers tab to title case in column C before using them as headers. Then build the HERE Matrix Routing distance table in the "Distance Matrix" tab using the normalized names.

When some customer rows have missing coordinates

Column A or B is blank for 4 customer rows, likely a data entry gap.

For customers in the Customers tab where column A or B is blank, write "Missing Coordinates" in column C and exclude those rows from the matrix call. For all other customers, run HERE Matrix Routing against the 5 depots and write the travel times to the "Distance Matrix" tab. List the excluded customers in a note in cell A1 of the Distance Matrix tab.

When you need a subset matrix for a single depot

Today only the Manchester depot is dispatching. You do not need the full 5×40 table.

Use HERE Matrix Routing to compute drive times from only the depot in row 2 of the Depots tab to all 40 customers in the Customers tab. Write the results as a single row per customer in the "Distance Matrix" tab, with customer name in column A and travel time in minutes in column B.

When you need the matrix plus a "nearest depot" assignment in one pass

The routing model needs the distance matrix and also needs each customer pre-assigned to their nearest depot.

Use HERE Matrix Routing to compute drive times between all 5 depots (Depots tab, columns A and B) and all 40 customers (Customers tab, columns A and B). Write the full 5×40 matrix to the "Distance Matrix" tab. Then in the Customers tab, add a "Nearest Depot" column (column C) for each customer, writing the name of the depot with the shortest travel time to that customer.

The pattern: matrix calculation and downstream assignment in one prompt, so the routing model gets both inputs without a second operation.

Try It

Get the 7-day free trial of SheetXAI and open any sheet with origin and destination coordinate data, then ask it to build a distance matrix using HERE. The HERE integration is included in every SheetXAI plan. See also how to calculate drive times from a fixed origin or the HERE in Google Sheets overview.

Stop memorizing formulas.
Tell your spreadsheet what to do.

Join 4,000+ professionals saving hours every week with SheetXAI.

Learn more