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

A new Data Days event is coming soon! This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. Don't miss out.

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
========================

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
Fabric SQL PBI Data Days

Data Days 2026 coming soon!

Sign up to receive a private message when registration opens and key events begin.

New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.