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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

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
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.