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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

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
November Power BI Update Carousel

Power BI Monthly Update - November 2025

Check out the November 2025 Power BI update to learn about new features.

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors