Forum Discussion
Spatial Join
- 5 months ago
To calculate the distance between two geograpical latitude and longitude locations using Haversine formula, you can follow the below dax pattern
FromLat = SELECTEDVALUE('From City'[lat]) FromLon = SELECTEDVALUE('From City'[lng]) ToLat = SELECTEDVALUE('To City'[lat]) Tolon = SELECTEDVALUE('To City'[lng]) Distance (km) = // Haversine/great-circle distance calculation adapted from Stack Overflow: https://stackoverflow.com/questions/27928/calculate-distance-between-two-latitude-longitude-points-haversine-formula VAR __latSelected = [FromLat] VAR __lonSelected = [FromLon] VAR __radius = 6371 VAR __multiplier = PI()/180 VAR __latDiff = (KeyMeasuresTable[ToLat]-__latSelected) * __multiplier VAR __lonDiff = (KeyMeasuresTable[Tolon]-__lonSelected) * __multiplier VAR __formula1 = SIN(__latDiff/2) * SIN(__latDiff/2) + COS(KeyMeasuresTable[ToLat] * __multiplier) * COS(__latSelected * __multiplier) * SIN(__lonDiff/2) * SIN(__lonDiff/2) VAR __formula2 = 2 * ATAN(DIVIDE(SQRT(__formula1),SQRT(1-__formula1))) VAR __distance = __radius * __formula2 RETURN __distanceBy calculating the distance between the cutomer and the delivery partner as per their geo location, you will able to identify the deliver partner who is nearest to the cusotmer. I believe this way you will be able to perform the spatial join.
Connect on LinkedIn
read my blogs here: techietips.co.in
Did I answer your question? Mark my post as a solution! If I helped you, click on the Thumbs Up to give Kudos.
Proud to be a Super User!
geographical proximity may not mean much (imagine both locations being on separate islands with no bridges and no ferry service). You will likely want to calculate actual distance based on road networks and road conditions. That's something you need to do with custom visuals or outside of Power BI.