Forum Discussion

HenryJS's avatar
HenryJS
Post Prodigy
6 years ago
Solved

Calculating Distance Between Latitude / Longitude

Hi all,

 

I have a matrix with candidates in rows and sites in columns.

 

I have placed the below measure into the values however it is showing the same distances between the candidates and sites for a lot and not calculating the correct distance.

 

The candidates/sites are joined to tables of candidate/site longitude/latitude.

 

How can I fix so it calculates the distance between the candidates/sites in the x/y axis?

 

I can share example data if required.

 

 

Distance From Compound = 

var Lat1 = MIN('Candidate Postcodes'[Column6])

var Lng1 = MIN('Candidate Postcodes'[Column7])




var Lat2 = MIN('Company Postcodes'[Column6])

var Lng2 = MIN('Company Postcodes'[Column7])

---- Algorithm here -----

var P = DIVIDE( PI(), 180 )

var A = 0.5 - COS((Lat2-Lat1) * p)/2 +

COS(Lat1 * p) * COS(lat2 * P) * (1-COS((Lng2- Lng1) * p))/2

var final = 12742 * ASIN((SQRT(A)))

return final