Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Balkrishnan
Helper II
Helper II

Distance between two Cities

I am getting Errow when calculating distance between two cities.

 I used this formula

PI_D180 = PI()/180
Distance = ACOS(SIN(Distance[Latitude_1]*[PI_D180])*SIN(Distance[Latitude_2]*[PI_D180])+COS(Distance[Latitude_1]*[PI_D180])*COS(Distance[Latitude_2]*[PI_D180])*COS((Distance[Longitude_2]*[PI_D180])-(Distance[Longitude_1]*[PI_D180])))*3959
 
Getting  error as
An argument of function 'ACOS' has the wrong data type or the result is too large or too small.
5 REPLIES 5
smpa01
Super User
Super User

In M through creating custom column with sample LAT format as 45.5105 (decimal degrees)

 

Lat1_Rad=([Latitude1]/180)*Number.PI
Lon1_Rad=([Longitude1]/180)*Number.PI
Lat2_Rad=([Latitude2]/180)*Number.PI
Lon2_Rad=([Longitude2]/180)*Number.PI
Distance_KM=Number.Acos(Number.Sin([Lat1_Rad]) * Number.Sin([Lat2_Rad]) + Number.Cos([Lat1_Rad]) * Number.Cos([Lat2_Rad]) * Number.Cos([Lon2_Rad]-[Lon1_Rad])) * 6371

 

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Thanks for your attention on this, but i need in Miles and need to  know how to use your formula in my calculation.

Anonymous
Not applicable

You can get the results in miles and then do a convertion multiplying the result by 1.6

Let me explain my use case.

This is my data

Distance.png

I need two filters as shown below

From City and Two City, When i select Dewitt and Bentonville, i need to know the distance between them.

I have two formula

PI_D180 = DIVIDE ( PI (), 180 )
and 
Distance = ACOS(SIN(Distance[Latitude_1]*[PI_D180])*SIN(Distance[Latitude_2]*[PI_D180])+COS(Distance[Latitude_1]*[PI_D180])*COS(Distance[Latitude_2]*[PI_D180])*COS((Distance[Longitude_2]*[PI_D180])-(Distance[Longitude_1]*[PI_D180])))*3959
 
But getting error...

Any help on this use case...

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.