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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
vicpinto
Regular Visitor

Finding distance between 2 points on the same table with additional criteria.

Hello all,

 

I have a table called SECTORS_4G_ENM with LAT and LON as well as some additional information like this:

vicpinto_1-1701287121480.png

 

 

Now I can calculate the shortest distance between any of these points using a formula I picked up from this forum. The formula is below and has been modified to work with this table:

 

Shortest Distance Type=
    VAR __baseLat = SECTORS_4G_ENM[LAT]
    VAR __baseLng = SECTORS_4G_ENM[LON]
    VAR __goldname = SECTORS_4G_ENM[GOLD_NAME]
    VAR P = DIVIDE ( PI(), 180 )
    VAR __distance =
    ADDCOLUMNS (
    FILTER(ALLSELECTED ( SECTORS_4G_ENM ),SECTORS_4G_ENM[GOLD_NAME]<>__goldname),
    "Distance",
        VAR Lat1 = __baseLat
        VAR Lng1 = __baseLng
        VAR Lat2 = SECTORS_4G_ENM[LAT]
        VAR Lng2 = SECTORS_4G_ENM[LON]
        VAR A = 0.5 - COS ( ( Lat2-Lat1 ) * P ) /2 +
            COS ( Lat1 * P ) * COS ( lat2 * P ) * ( 1 - COS ( ( Lng2- Lng1 ) * P ) ) / 2
        VAR final = 12742 * ASIN ( ( SQRT ( A ) ) )
        RETURN final
    )
    VAR minVal_ = MINX ( __distance, [Distance] )
RETURN
MINX ( FILTER ( __distance, [Distance] = minVal_), SECTORS_4G_ENM[SITE_TYPE] )
 

However, this returns the shortest distance to any SITE_TYPE - Big or Small. This is not what i want to acomplish.

 

What I want to acomplish is the for every GOLD_NAME, regardless of whether it is Big or Small type, return the shortest distance to the nearest SITE_TYPE that is Big.

 

Thanks in advance.

1 REPLY 1
lbendlin
Super User
Super User

Please provide sample data that fully covers your issue.
Please show the expected outcome based on the sample data you provided.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.