Forum Discussion

Anam's avatar
Anam
Regular Visitor
9 years ago
Solved

Distance Calculation in Power BI

Hey,

I wanted to know that once I have plotted several locations on a map in Power BI, how can I calculate the distance between any two locations?

15 Replies

  • v-sihou-msft's avatar
    v-sihou-msft
    Microsoft Employee

    Anam

     

    You need Latitude and Longitude 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 can achieve it via either Power Query or DAX method.

     

    Or you can use Google Map API as cs_skit suggested.

     

    Regards,

    • oolamide85's avatar
      oolamide85
      Frequent Visitor

      Can I have the distances data exported out in Excel?

    • JJH_'s avatar
      JJH_
      Frequent Visitor

      Anam What's the metric (KM, M, CM) that should apply to the result of applying this formula?

    • CJ7's avatar
      CJ7
      New Member

      Cant You just do euclidean distance -> sqrt((lat1-lat2)^2+(lon1-lon2)^2)*110.574 km ? 

      Also Why do wee need to get geocode from other sources like Google ( paid ), when power BI does locate cities on the map - therefore it could just give us direct answer regarding the longitude and latitude of certain city.

    • Anam's avatar
      Anam
      Regular Visitor

      How do I use Google Maps API in Power BI?

      • Anonymous's avatar
        Anonymous
        Not applicable

        How about if you have 3 tables, one telling where from shipped, one telling where to shipped and third one which is having cities and latitube and longitudes? how to combine all of those.