- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Finding the second smallest distance between points with dynamic coordinates defined by measures
Hi,
For each point I'm trying to find the 5 closest points. The x, y, and z coordinates for each point are defined by measures whose values change depending on user selection.
I've succeeded in determining the closest point. However, I'm struggling with finding the second closest point.
This is the measure I've used for finding the closest point:
Dist =
var x0 = CALCULATE([x],FILTER('Dim Butik',SELECTEDVALUE('Dim Butik'[ButikID])))
var y0 = CALCULATE([y],FILTER('Dim Butik',SELECTEDVALUE('Dim Butik'[ButikID])))
var z0 = CALCULATE([z],FILTER('Dim Butik',SELECTEDVALUE('Dim Butik'[ButikID])))
var _Table =
ADDCOLUMNS(
FILTER(ALL('Dim Butik'),'Dim Butik'[ButikID]<>SELECTEDVALUE('Dim Butik'[ButikID])),
"distance", SQRT(POWER([x]-x0,2)+POWER([y]-y0,2)+POWER([z]-z0,2)))
var _min1 = CALCULATE(MINX(_Table,[distance]))
var min1 = CALCULATE(MIN('Dim Butik'[ButikID]),FILTER(_Table,[distance]=_min1))
return min1
I've tried finding the next point min2 using a filter expression with [ButikID] <> min1 but I couldn't get it to work. I've also tried using RANKX but I can't get that to work either.
Any help would be much appreciated.
Edit:
https://drive.google.com/file/d/1BzCfkNdP7LdWMyPhI2O533g_l5d-HBRQ/view?usp=sharing
File uploaded with sample data and expected results^
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Solved it with the addition:
var _min2 = MINX(FILTER(_Table,[distance]>_min1),[distance])
var min2 = MINX(FILTER(_Table,[distance]=_min2),'Dim Butik'[ButikID])

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Solved it with the addition:
var _min2 = MINX(FILTER(_Table,[distance]>_min1),[distance])
var min2 = MINX(FILTER(_Table,[distance]=_min2),'Dim Butik'[ButikID])
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@Anonymous
Your 2nd smallest min could be this:
var min1 = MINX ( FILTER ( _Table, [distance] > _min1 ), 'Dim Butik'[ButikID] )
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

Thank you for the reply.
Unfortunately, it doesn't quite seem to get the job done. I added
var min2 = MINX(FILTER(_Table,[distance]>_min1),'Dim Butik'[ButikID])
and returned both min1 and min2. This is some of the results:
That can't be right.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

@Anonymous
If you could share a PBIX file with sample data and the expected result, it would be easier.
⭕ Subscribe and learn Power BI from these videos
⚪ Website ⚪ LinkedIn ⚪ PBI User Group
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content

https://drive.google.com/file/d/1BzCfkNdP7LdWMyPhI2O533g_l5d-HBRQ/view?usp=sharing
File uploaded with sample data and expected results^

Helpful resources
Subject | Author | Posted | |
---|---|---|---|
08-30-2023 10:40 AM | |||
07-30-2024 08:10 AM | |||
08-20-2024 09:13 AM | |||
08-13-2024 03:27 AM | |||
08-12-2024 01:56 PM |
User | Count |
---|---|
128 | |
123 | |
85 | |
59 | |
47 |