Forum Discussion
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
Sure, would really need to see some sample data. I created a measure for doing exactly this HenryJS so perhaps comparing your PBIX with the one included here: https://community.powerbi.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/963267#M423
2 Replies
- amitchandakSuper User
Greg_Deckler , Please provide your input on this.
- Greg_DecklerCommunity Champion
Sure, would really need to see some sample data. I created a measure for doing exactly this HenryJS so perhaps comparing your PBIX with the one included here: https://community.powerbi.com/t5/Quick-Measures-Gallery/Going-the-Distance/m-p/963267#M423