Forum Discussion

unknown917's avatar
unknown917
Helper IV
10 months ago
Solved

Azure Map Point ID, Order help

I have a table with a starting point and multiple end points.  I have calculated the distance and cardinal direction from the starting point to each of the end points.  I now wish to take the most ou...
  • tayloramy's avatar
    tayloramy
    10 months ago

    Hi unknown917

     

    The idea is that you want to rank the entries by distance, and then keep only the ones where rank = 1. 

    Something along the lines of this: 

    RankInBin =
    VAR sp  = 'Table'[StartingPoint]
    VAR bin = 'Table'[DirBin]
    RETURN
        RANKX(
            FILTER(
                ALL('Table'),
                'Table'[StartingPoint] = sp
                    && 'Table'[DirBin] = bin
            ),
            'Table'[DistanceKm],
            ,
            DESC,
            DENSE
        )

     

    Next create a slim table of “farthest points” by filtering to RankInBin = 1:

    OutlierPoints =
    FILTER(
        'Table',
        'Table'[RankInBin] = 1
    )

    If you sometimes get multiple rows with the exact same max distance, add a secondary tiebreaker to the rank. One simple way is build a SortKey column and rank by that:

    SortKey = 'Table'[DistanceKm] * 1000000 + (360 - 'Table'[BearingDeg]) / 1000


    Then change the RANKX expression to use [SortKey] instead of DistanceKm, still DESC.

     

    If you found this helpful, consider giving some Kudos. If I answered your question or solved your problem, mark this post as the solution.