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
Krcmajster
Helper IV
Helper IV

Find top n closest locations based on lng and lat

Hi All, 

 

Based on lng and lat I want to find top 10 closest locations when using drillthrough on specific cost center. Any ideas?

 

 

3 REPLIES 3
Anonymous
Not applicable

Hi @Krcmajster 

 

Maybe you can do something like below:

 

Distance = 
VAR __cc = SELECTEDVALUE( dimCC[Site Name]; FIRSTNONBLANK( dimCC[Site Name]; 1))
VAR __siteLat = CALCULATE( MAX( dimCC[Lat]); dimCC[Site Name] = __cc)
VAR __siteLong = CALCULATE( MAX( dimCC[Lon]); dimCC[Site Name] = __cc)

RETURN
    // Distance in km
    ACOS( 
        COS( RADIANS( 90 - MAX( DimXX[lat])))*
        COS( RADIANS( 90 - __siteLat)) + 
        SIN( RADIANS( 90 - MAX( DimXX[lat])))* 
        SIN( RADIANS( 90 - __siteLat)) *
        COS( RADIANS( MAX( DimXX[long]) - __siteLong))
        )*6371 

 

And then create a TOPN measure:

 

top10 = 
TOPN(
    10;
    SUMMARIZE(
        DimXX;
        "Distance"; [Distance]
    );
    [Distance]; ASC
)

 

It is not the fastest measure if you have many observations, but I believe it will work. If you have a lot of observations you should consider moving the calculations to the queries.

 

If this answer helps then please mark it as the accepted solution. Kudos is also appreciated.

@Anonymous Thanks

 

So in my case let's say it would look like this:

 

Distance =
   VAR __cc = SELECTEDVALUE( Property'[BuildingName], FIRSTNONBLANK(Property'[BuildingName], 1))
   VAR __siteLat = CALCULATE( MAX( Property'[Latitude]), Property'[BuildingName] = __cc)
   VAR __siteLong = CALCULATE( MAX(Property'[Longitude]), 'Property'[BuildingName] = __cc)

RETURN
// Distance in km
  ACOS(
  COS( RADIANS( 90 - MAX( Property'[Latitude])))*
  COS( RADIANS( 90 - __siteLat)) +
  SIN( RADIANS( 90 - MAX( 'Property_'[Latitude])))*
  SIN( RADIANS( 90 - __siteLat)) *
COS( RADIANS( MAX(Property'[Longitude]) - __siteLong))
)*6371
 
top10 =
  TOPN(
  10,
  SUMMARIZE(
  Property',
  "Distance", [Distance]
 ),
  [Distance],ASC
  )
 
Will the drill through affect the measures?
Anonymous
Not applicable

Hi @Krcmajster 

 

I'm not quite sure that it will and neither that the TOPN function works as it should. But it is just an idea which might be able to lead you in the right direction.

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.