2 Replies Latest reply on Oct 6, 2017 2:17 PM by Siddharth Patil

# Calculate distance between two zip codes

I am trying to calculate the distance between two zip codes. I have a dataset that contains two zip codes (customer zip & retail zip) as well as one dimension - sales (units). I would like to calculate the distance between store and customer to use as a filter - and to know as an average.

I've found this code for calculating distance

3959 * ACOS

(

SIN(RADIANS([Lat])) * SIN(RADIANS([Lat2])) +

COS(RADIANS([Lat])) * COS(RADIANS([Lat2])) * COS(RADIANS([Long2]) - RADIANS([Long]))

)

But cannot figure out how to identify the latitude/longitude of a specific zip.

• ###### 1. Re: Calculate distance between two zip codes

Hi Nick-

That logic will work only with the Lat/Long and you have to give it a starting point for the calc.

Check out my beer map that uses that logic.  You can download it and pull it apart.

As far as getting zip lat/longs, you can get them here, but beware zip code data can be fluid.

Free Zip Code Latitude and Longitude Database

2 of 2 people found this helpful
• ###### 2. Re: Calculate distance between two zip codes

Wow Adam, this is Awesome.

Regards,

Siddharth