cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anam Frequent Visitor
Frequent Visitor

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?

3 ACCEPTED SOLUTIONS

Accepted Solutions
cs_skit Member
Member

Re: Distance Calculation in Power BI

do you have LAT and LONG? If yes you can do it with math:

https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-h...

 

if not you need to custom call Bing Maps or Google Maps APIs for that

Moderator v-sihou-msft
Moderator

Re: Distance Calculation in Power BI

@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,

Super User
Super User

Re: Distance Calculation 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


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

12 REPLIES 12
cs_skit Member
Member

Re: Distance Calculation in Power BI

do you have LAT and LONG? If yes you can do it with math:

https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-h...

 

if not you need to custom call Bing Maps or Google Maps APIs for that

Moderator v-sihou-msft
Moderator

Re: Distance Calculation in Power BI

@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,

Anam Frequent Visitor
Frequent Visitor

Re: Distance Calculation in Power BI

How do I use Google Maps API in Power BI?

Super User
Super User

Re: Distance Calculation 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


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Highlighted
ShrikantKhanna Regular Visitor
Regular Visitor

Re: Distance Calculation in Power BI

This post is great but can anyone assist in calculating distance between two postcodes ?

oolamide85 Frequent Visitor
Frequent Visitor

Re: Distance Calculation in Power BI

Can I have the distances data exported out in Excel?

GuySev Frequent Visitor
Frequent Visitor

Re: Distance Calculation in Power BI

Fantastic blog, worked great for me

Re: Distance Calculation in Power BI

But how can we integrate it to Power bi?

Re: Distance Calculation in Power BI

But How to Integrate it into power bi?