Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

How to calculate lat/long distance

I have an example table below with lat/longs, what I'm trying to figure out is there a way to input unique lat/longs and have that calculate the distance to the lat/long in the table below. Thanks again for the help.

 

ReceptionLatitudeLongitude
CARLSBADR32.46959-104.137
CARR     40.88491-104.867
CASPER   42.85017-106.351
CBEAUMONT30.04742-94.0736
CDICKINSN29.46067-95.0451
CHANNELVW29.76388-95.1027
CHARENTON29.87393-91.5207
CHEROKEE36.7986-98.3595
CHILDRESS34.38211-100.263
CHINAGR32.52974-100.821
1 ACCEPTED SOLUTION
V-pazhen-msft
Community Support
Community Support

@Anonymous 

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 (6371 is Earth radius in km.)

 

For your requirement there are also Power Query or DAX method.


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

View solution in original post

9 REPLIES 9
MightyBiiish
New Member

Be careful! The accepted answer does not include the step of converting Degrees to Radians. You will get a very different answer if you do not convert to radians.

The final formula should be:

 

=ACOS((SIN(RADIANS(Lat1)) * SIN(RADIANS(Lat2))) + (COS(RADIANS(Lat1)) * COS(RADIANS(Lat2))) * (COS(RADIANS(Lon2) - RADIANS(Lon1)))) * 6371

 

 

This calculates distance (in kilometers) between two points on the surface of the Earth as a sphere.

 

Also note:

  • There will be some inaccuracy because we're using an average for the Earth's radius
  • There may also be some inaccuracy from rounding (I get slightly different results when using a calculator)
Wiktorek
New Member

Use Google Earth.

Not terribly helpful... . One set of points? Sure. But if you have 50 and you want the top 5 shortest? User won't wait while you run that api 50 times to determine the shortest.

V-pazhen-msft
Community Support
Community Support

@Anonymous 

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 (6371 is Earth radius in km.)

 

For your requirement there are also Power Query or DAX method.


Paul Zheng _ Community Support Team
If this post helps, please Accept it as the solution to help the other members find it more quickly.

Thank you very much for your information.

However, I wonder the distance is a straight line distance between two points or a curved distance on the Earth?

I would like to appreciate very much if you can anwser this question.

blopez11
Super User
Super User

Anonymous
Not applicable

That's actually pretty slick as well but won't work for what I'm trying to accomplish. I need to input certain lat/longs in then calculate the distance to the closest reception point. 

You can either hardcode in the Haversine formula (or other formula) to calculate distance from lat/long inputs, or you could use a web api to send the lat/log for start and finish to get the distance.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Are you saying send the points to a service that calculates the distance using street maps? Otherwise, using a web service to run a simple Haversine, et. al., makes little sense.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.