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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
tanvi_m
Frequent Visitor

Rank based on distance measure

I have three tables which i am using in order to calculate the distance between two lat/longs. 

 

Table A : 

X, lat , long

 

Table " From A"  : 

From A = SUMMARIZECOLUMNS(

'A'[X],
'A'[LATITUDE],
'A'[LONGITUDE]
)

 

Table B:

 SITE ID CI128 HXL = SUMMARIZECOLUMNS('A'[X])

 

measure to calculate distance : 

mile =
var lat1 = min('From A'[LATITUDE])
var lng1 = min('From A'[LONGITUDE])
var lat2 = min ('A'[LATITUDE])
var long2 = min ('A'[LONGITUDE])
var P = divide (pi(),180)
var A = 0.5 - cos((lat2-lat1)*p)/2+
cos(lat1*p)*cos(lat2*p)*(1-cos((long2-lng1)*p))/2
var final = 0.621 * (12742 * asin((sqrt(A))))
return final
 
Now I have my distance calculated perfectecly when I put following entries in the table frmat 
 
X(Source - coming from table A) | X(Target - coming from table "From A) | mile  . 
 
Now I need to write a measure in order to rank them based on their distances 
 
X(source) | X(Target) | mile |  RANK (?) 
 
Could anyone please help me with the same ? 
 
Thanks 
2 REPLIES 2
tanvi_m
Frequent Visitor

Tom, 

Thankyou for the response . 

Here’s the complete details on data structure 

 

Table A : 

LONGITUDE

LATITUDE

X

-96.6

32.9

A

-96.9

33

B

-96.5

32

C

-97.7

31

D

-96

32.2

A

-97

32.1

B

-96.5

33

E

-97.7

31

X

 

Table B = SUMMARIZECOLUMNS('A'[X])

From A = SUMMARIZECOLUMNS(

'A'[X],

'A'[LATITUDE],

'A'[LONGITUDE]

)

 

OUTPUT TABLE : 

X (coming from table A)

X(Coming from table From A)

Distance(miles)

A

C

14.99815

C

A

14.99815

A

B

24.38354

B

A

24.38354

 

Now I need to rank column [ X(Coming from table From A) ] based on values in column " distance(miles)" . 

Hope this explains the query in details.. 

 

Thankyou 

Tanvi 

 

 

TomMartens
Super User
Super User

Hey,

 

please provide a pbix file that contains some sample data, but still represents the data model, upload the file to onderive, dropbox, and share the link (if you use xlsx for the data creation, upload the xlsx file as well).

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.