Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by watching the DP-600 session on-demand now through April 28th.
Learn moreJoin the FabCon + SQLCon recap series. Up next: Power BI, Real-Time Intelligence, IQ and AI, and Data Factory take center stage. All sessions are available on-demand after the live show. Register now
I need help calculate distance using lat and long information.
Using math formula shown below (its' tested and working but when source and target lat and long information is in same table)
In this scenario, one table I have Source and target and need distance between them and the lat and long values needs to be looked up from another table.
Any help is appreciated. Thanks.
| From | To | Distance (Miles) |
| Berlin | Tokyo | ? |
| Mumbai | New York | ? |
| London | Paris | ? |
| City | Lat | Long |
| Berlin | 39.58305 | -74.78388977 |
| Mumbai | 39.55434 | -74.74279785 |
| London | 39.51902 | -74.69287872 |
| Tokyo | 39.48972 | -74.59777832 |
| New York | 39.45287 | -74.63844299 |
| Paris | 39.43 | -74.57861328 |
------------------------------------------
Sample
-------------------------------------------
Solved! Go to Solution.
Distance =
var Lat1=LOOKUPVALUE(Locations[Lat],Locations[City],SELECTEDVALUE(Distances[From]))
var Lng1=LOOKUPVALUE(Locations[Long],Locations[City],SELECTEDVALUE(Distances[From]))
var Lat2 =LOOKUPVALUE(Locations[Lat],Locations[City],SELECTEDVALUE(Distances[To]))
var Lng2 =LOOKUPVALUE(Locations[Long],Locations[City],SELECTEDVALUE(Distances[To]))
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
return 12742 * ASIN((SQRT(A)))
see attached.
Distance =
var Lat1=LOOKUPVALUE(Locations[Lat],Locations[City],SELECTEDVALUE(Distances[From]))
var Lng1=LOOKUPVALUE(Locations[Long],Locations[City],SELECTEDVALUE(Distances[From]))
var Lat2 =LOOKUPVALUE(Locations[Lat],Locations[City],SELECTEDVALUE(Distances[To]))
var Lng2 =LOOKUPVALUE(Locations[Long],Locations[City],SELECTEDVALUE(Distances[To]))
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
return 12742 * ASIN((SQRT(A)))
see attached.
Thanks! you're the best.
Check out the April 2026 Power BI update to learn about new features.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
| User | Count |
|---|---|
| 41 | |
| 37 | |
| 34 | |
| 21 | |
| 16 |
| User | Count |
|---|---|
| 65 | |
| 62 | |
| 31 | |
| 26 | |
| 25 |