Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Calculate distance between Zip Codes?

I have a table with two fields as zip codes. An origination  zip code and a destination zip code. I would like to calculate the milage between the two zip codes. How would I do this?

  • Hi Anonymous ,

     

    The Latitude and Longitude are needed to calculate the distance between two locations with following formula:

     

    =acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1))*6371    (Ps: 6371 is Earth radius in km.)

     

    You may also achieve it via either Power Query or DAX method. Or you can use Google Map API .

     

    Best Regards,

    Amy 

     

    Community Support Team _ Amy

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

4 Replies

  • mahoneypat's avatar
    mahoneypat
    Icon for Microsoft Employee rankMicrosoft Employee

    I would do this in the Query Editor.  With a table that has the two zipcode columns, you can add a custom column that makes a web call to a REST API that does this.  Here is an example one - http://www.zipcodeapi.com/API#distance

    You can get a free key, and then concatenate the values from your two columns into the needed URL.

     

    If this works for you, please mark it as solution.  Kudos are appreciated too.  Please let me know if not.

    Regards,

    Pat

    • Anonymous's avatar
      Anonymous
      Not applicable

      Can you please give me more direction  add custom column that makes a web call to a REST API that does this? I've never used an API before so this is foreign to me.

  • v-xicai's avatar
    v-xicai
    Icon for Community Support rankCommunity Support

    Hi Anonymous ,

     

    The Latitude and Longitude are needed to calculate the distance between two locations with following formula:

     

    =acos(sin(lat1)*sin(lat2)+cos(lat1)*cos(lat2)*cos(lon2-lon1))*6371    (Ps: 6371 is Earth radius in km.)

     

    You may also achieve it via either Power Query or DAX method. Or you can use Google Map API .

     

    Best Regards,

    Amy 

     

    Community Support Team _ Amy

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.