Forum Discussion
akarasick1
6 years agoFrequent Visitor
Calculating minimum distance between XY coordinates
I'm trying to determine the closest point to any given point on an XY scatterplot. For simplicity, data is plotted on a 10x10 XY axis. How can I calculate the minimum distance from each point to any ...
- 6 years ago
Probably something like:
Distance = VAR x1 = SELECTEDVALUE(Locations[X]) VAR y1 = SELECTEDVALUE(Locations[Y]) VAR __Table = ADDCOLUMNS( FILTER(ALL(Locations),[X] <> x1 && [Y] <> y1) "distance",SQRT(POWER(([X] - x1),2) + POWER(([Y] - y1),2)) RETURN MINX(__Table,[distance]) - 6 years agoWell, that's what I was trying to do with that filter. You would need some kind of ID or Index. So if you had that identifier, just grab the identifier with a SELECTEDVALUE and then filter on that identifier <> that.
Greg_Deckler
Community Champion
6 years agoProbably something like:
Distance =
VAR x1 = SELECTEDVALUE(Locations[X])
VAR y1 = SELECTEDVALUE(Locations[Y])
VAR __Table =
ADDCOLUMNS(
FILTER(ALL(Locations),[X] <> x1 && [Y] <> y1)
"distance",SQRT(POWER(([X] - x1),2) + POWER(([Y] - y1),2))
RETURN
MINX(__Table,[distance])akarasick1
6 years agoFrequent Visitor
Thank you, Greg. This definitely works!
The only tweak I'd need is that I can't exclude points that match the selected X or Y. Any way to just remove the given point and not all related x/y values?
- Greg_Deckler6 years ago
Community Champion
Well, that's what I was trying to do with that filter. You would need some kind of ID or Index. So if you had that identifier, just grab the identifier with a SELECTEDVALUE and then filter on that identifier <> that.- akarasick16 years agoFrequent Visitor
Perfect. Thanks!