Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
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.
Solved it with the addition:
var _min2 = MINX(FILTER(_Table,[distance]>_min1),[distance])
var min2 = MINX(FILTER(_Table,[distance]=_min2),'Dim Butik'[ButikID])
Solved it with the addition:
var _min2 = MINX(FILTER(_Table,[distance]>_min1),[distance])
var min2 = MINX(FILTER(_Table,[distance]=_min2),'Dim Butik'[ButikID])
@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
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.
@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
https://drive.google.com/file/d/1BzCfkNdP7LdWMyPhI2O533g_l5d-HBRQ/view?usp=sharing
File uploaded with sample data and expected results^
Check out the November 2025 Power BI update to learn about new features.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
| User | Count |
|---|---|
| 97 | |
| 73 | |
| 50 | |
| 47 | |
| 44 |