Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
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?
Solved! Go to Solution.
do you have LAT and LONG? If yes you can do it with math:
if not you need to custom call Bing Maps or Google Maps APIs for that
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,
I did a blog post on calculating the direct line distance between two points in DAX
http://radacad.com/dynamic-distances-in-power-bi
But how can we integrate it to Power bi?
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,
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 What's the metric (KM, M, CM) that should apply to the result of applying this formula?
Can I have the distances data exported out in Excel?
do you have LAT and LONG? If yes you can do it with math:
if not you need to custom call Bing Maps or Google Maps APIs for that
But How to Integrate it into power bi?
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.
How do I use Google Maps API in Power BI?
I did a blog post on calculating the direct line distance between two points in DAX
http://radacad.com/dynamic-distances-in-power-bi
This worked awesome, thank you!!!!
Thank you for this post, If I want to use ArcGIS map and I pointed on a City then I want to determine the nearest cities within (x) kilometers radius how can we do this?
Hello,
Did you get any answers? I have similar problem 🙂
Thanks.
Fantastic blog, worked great for me
This post is great but can anyone assist in calculating distance between two postcodes ?
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
92 | |
87 | |
84 | |
65 | |
49 |
User | Count |
---|---|
140 | |
114 | |
110 | |
59 | |
59 |