Forum Discussion
Distance (in kilometers) between adresses
- 1 year ago
You can use the Haversine formula to calculate the distance between two geo coordinates (must be a pair of latitude and longitude).
Distance in KM = // Haversine Formula VAR EarthRadiusKm = 6371.0 VAR Lat1 = RADIANS ( SELECTEDVALUE ( 'FromLocation'[Latitude] ) ) VAR Lat2 = RADIANS ( SELECTEDVALUE ( ToLocation[Latitude] ) ) VAR Lon1 = RADIANS ( SELECTEDVALUE ( 'FromLocation'[Longitude] ) ) VAR Lon2 = RADIANS ( SELECTEDVALUE ( ToLocation[Longitude] ) ) VAR DeltaLat = Lat2 - Lat1 VAR DeltaLon = Lon2 - Lon1 VAR a = POWER ( SIN ( DIVIDE ( DeltaLat, 2 ) ), 2 ) + COS ( Lat1 ) * COS ( Lat2 ) * POWER ( SIN ( DIVIDE ( DeltaLon, 2 ) ), 2 ) VAR c = 2 * ASIN ( SQRT ( a ) ) RETURN EarthRadiusKm * c
You can use the Haversine formula to calculate the distance between two geo coordinates (must be a pair of latitude and longitude).
Distance in KM =
// Haversine Formula
VAR EarthRadiusKm = 6371.0
VAR Lat1 =
RADIANS ( SELECTEDVALUE ( 'FromLocation'[Latitude] ) )
VAR Lat2 =
RADIANS ( SELECTEDVALUE ( ToLocation[Latitude] ) )
VAR Lon1 =
RADIANS ( SELECTEDVALUE ( 'FromLocation'[Longitude] ) )
VAR Lon2 =
RADIANS ( SELECTEDVALUE ( ToLocation[Longitude] ) )
VAR DeltaLat = Lat2 - Lat1
VAR DeltaLon = Lon2 - Lon1
VAR a =
POWER ( SIN ( DIVIDE ( DeltaLat, 2 ) ), 2 )
+ COS ( Lat1 ) * COS ( Lat2 )
* POWER ( SIN ( DIVIDE ( DeltaLon, 2 ) ), 2 )
VAR c =
2 * ASIN ( SQRT ( a ) )
RETURN
EarthRadiusKm * c
- Henrique_Quint1 year ago
Helper I
Hi, danextian !
This formula worked. But is there an easier way to get latitude and logitude based on adresses? I'm doing manually but there is more than one thousand deliveries since the beggining of the year.
Any ideas on how to do it?- Anonymous1 year agoNot applicable
Hi Henrique_Quint,
- If you're comfortable with Python, you can use libraries like geopy or requests to call geocoding APIs and convert multiple addresses into latitude and longitude in batches.
- If you prefer using Power Automate, you can set up a flow to automate the process of geocoding addresses using an API.
If you like coding and want more control over the process, Python is a powerful option.
If you're more comfortable with no-code solutions and are already using the Microsoft ecosystem, Power Automate is an excellent choice. It allows you to create workflows without writing code.
Regards,
Vinay Pabbu