March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe 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
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.
Reception | Latitude | Longitude |
CARLSBADR | 32.46959 | -104.137 |
CARR | 40.88491 | -104.867 |
CASPER | 42.85017 | -106.351 |
CBEAUMONT | 30.04742 | -94.0736 |
CDICKINSN | 29.46067 | -95.0451 |
CHANNELVW | 29.76388 | -95.1027 |
CHARENTON | 29.87393 | -91.5207 |
CHEROKEE | 36.7986 | -98.3595 |
CHILDRESS | 34.38211 | -100.263 |
CHINAGR | 32.52974 | -100.821 |
Solved! Go to Solution.
@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.
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:
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.
@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.
I have used the following as reference in the past
https://dataveld.com/2019/03/20/display-points-within-a-distance-radius-on-a-power-bi-map/
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
To learn more about Power BI, follow me on Twitter or subscribe 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.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
125 | |
85 | |
69 | |
54 | |
45 |
User | Count |
---|---|
204 | |
105 | |
98 | |
65 | |
54 |