Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
Hello everyone,
I'm working on a Power BI report with data that includes X and Y coordinates for each item. I'd like to implement a feature that allows users to select an item and see a list or table displaying the closest items to it. I was able to calculate the distance of each item to a fixed coordinate in a column, but I couldn’t make that reference coordinate change based on the item selected in the slicer.
Thank you in advance for any suggestions or DAX examples you can provide!
Solved! Go to Solution.
Hi @LeopoldoG ,
You can the following expression to get the coordinates in the slicer:
SelectedItemX =
CALCULATE(
MAX('Table'[X]),
'Table'[CT] = SELECTEDVALUE('Table'[CT])
)
SelectedItemY =
CALCULATE(
MAX('Table'[Y]),
'Table'[CT] = SELECTEDVALUE('Table'[CT])
)
Hope it helps!
Best regards,
Community Support Team_ Scott Chang
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Hi @LeopoldoG ,
Not sure about your data model, but you can generally try the following expression:
SelectedX = SELECTEDVALUE(YourTable[X])
SelectedY = SELECTEDVALUE(YourTable[Y])
Distance =
VAR SelectedX = [SelectedX]
VAR SelectedY = [SelectedY]
RETURN
SQRT(POWER(YourTable[X] - SelectedX, 2) + POWER(YourTable[Y] - SelectedY, 2))
Rank =
RANKX(
ALL(YourTable),
[Distance],
,
ASC
)
Hope it helps!
Best regards,
Community Support Team_ Scott Chang
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
Thank you for your response! I actually tried something similar, but it doesn’t work as expected. It calculates the distance between each item and itself, rather than using the coordinates of the selected item in the slicer.
The data model:
Hi @LeopoldoG ,
You can the following expression to get the coordinates in the slicer:
SelectedItemX =
CALCULATE(
MAX('Table'[X]),
'Table'[CT] = SELECTEDVALUE('Table'[CT])
)
SelectedItemY =
CALCULATE(
MAX('Table'[Y]),
'Table'[CT] = SELECTEDVALUE('Table'[CT])
)
Hope it helps!
Best regards,
Community Support Team_ Scott Chang
If this post helps then please consider Accept it as the solution to help the other members find it more quickly.
@LeopoldoG This should be helpful. If you can provide sample data, I can probably modify this to work for what you are trying to do: Near - Microsoft Fabric Community
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
24 | |
12 | |
10 | |
10 | |
10 |
User | Count |
---|---|
17 | |
15 | |
12 | |
11 | |
10 |