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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! 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
Community Champion
Community Champion

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: Live Sound
• Beautiful News: Women in Parliament, Energy Mix, Shrinking Armies
• Visual Capitalist: Working Hrs
• Others: Easing Graph, Animated Calendar
MayViz Submissions
• Week 1: View
• Week 2: View
• Week 3: View
• Week 4: View
========================

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
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.