Forum Discussion

John896478's avatar
John896478
New Member
5 months ago
Solved

Spatial Join

Bonjour,   Sur Power Bi, je voudrai s'il vous plaît faire une jointure spatiale entre les coordonnées géographiques des clients (table 1) et les coordonnées géograhiques des points enregistrés dans...
  • tharunkumarRTK's avatar
    5 months ago

    John896478 

     

    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 __distance 

     

    By 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!