Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
DanSanDST
Helper I
Helper I

Getting what Name or Id is a point inside multiple Polygons

Greetings, i managed to get an algorithm that calculates if a point (LAT, LONG) is inside a polygon (arranged as an LAT/LONG edges table). It returns True or False, but now i also need whats the name of the polygon the point its in.

 

If i say it to return the FIRSTNONBLANK(Poligonos[name], Poligonos[Name]), it just returns the first check on all the polygons it did, so its the same name for all. I need it to work by blocks, since i have a "name" column for each polygon, so if it returns true on that block, it goes outside the loop and give me that "name" as the result.

 

Im also trying to optimize the code so it doesnt have to test every polygon for each point. Its thousand points against about 100 polygons wich each one with about 1000 points/edges (it takes a lot to calculate). I have a "zone" name on the points table and a "zone" on the polygons, so i could match those first before go into the loop.

 

 

My DAX code for the algorirthm

 

DanSanDST_0-1753454821628.png

 

 

The edges tables with x, y, meaning lat and long. (doing this table from a .KML was some work)

 

DanSanDST_1-1753454968581.png

 

9 REPLIES 9
v-hashadapu
Community Support
Community Support

Hi @DanSanDST , Hope you're doing okay! May we know if it worked for you, or are you still experiencing difficulties? Let us know — your feedback can really help others in the same situation.

v-hashadapu
Community Support
Community Support

Hi @DanSanDST , hope you are doing great. May we know if your issue is solved or if you are still experiencing difficulties. Please share the details as it will help the community, especially others with similar issues.

DanSanDST
Helper I
Helper I

The algoritm actually works for the sample data im using (a single zone) i havent tested it for all the zones since it takes some time to calculate it.

 

first what im trying to do is this (calculated column):

 

DanSanDST_0-1753462636628.png

Making the algorithm loop for "id zone" then "id polygon", and the column should return the id zone, id polygon and polygon name so i can split the column in the 3 values.

 

some data example to calculate would be: Polygon edges table for squares, please asume its a complex polygon, whats important is to get the other columns when the algorithm calculates with all the rows on this polygons table.

id zoneid polpol namelat0long0lat1long1
11A1112
11A1222
11A2221
11A2111
12B2224
12B2444
12B4442
12B4222
23C4448
23C4888
23C8884
23C8444
34D88816
34D8161616
34D1616168
34D16888

 

points to test

point idlatlong
12030
233
33040
455
51010
666
75060
81.51.5

 

Expected result:

point idlatlongPoint in Poly
12030Outside
2331 2 B
33040Outside
4552 3 C
510103 4 D
6662 3 C
75060Outside
81.51.51 1 A

 

like i said, if the point is inside or not is covered, im missing first: getting the zone and name data for when it finds what polygon is into. And trying to at least filter the calculation for each zone, since both the polygon and values to find tables have a "zone", but it would need to be a loop so it searches the data for each zone with its zone on the polygon table. I cant have a table for each polygon since i need it to be automated, for when new polygons are added or removed.

please check your zone sample data. All of the "zones"  are  lines, not rectangles.  A point cannot be "in"  a zone in that case.

The algorithm works with an Edges table, meaning in a line you need x0/y0 and x1/y1 to make a segment. 

 

The real polygons are complex and the algorithm works fine

 

DanSanDST_0-1753481996252.png

 

Hi @DanSanDST , Thank you for reaching out to the Microsoft Community Forum.

 

We reproduced your setup and built a DAX calculated column that filters polygons by zone, groups edges by polygon, applies the ray-casting algorithm per group and returns the first polygon that contains the point. If none match, it returns Outside. This gives you exactly what you need, dynamically, without hardcoding.

 

Please check the attached .pbix file for reference.

 

That said, this approach won't scale well. DAX has no spatial engine and evaluating every polygon’s edges per point is expensive. For larger datasets, I recommend moving this logic to Power Query or a Fabric notebook, where spatial operations are more efficient and maintainable.

Thanks, ill test it once im home (my pc is faster).

 

I already was trying to solve it via Power Query and i managed to accomplish it (with some help from the community too). Its still taking on my PC about 15-20 mins to calculate for about 90k rows. Now im recalculating for some changes in the polygons area and its already on 23mins for 18k rows (a slower lapton, i5 gen 11 16gb ram).

Hi @DanSanDST , Thanks for the update and the information. Please do share your thoughts after checking it.

Thank you.

lbendlin
Super User
Super User

That algorithm will only work for very simple polygons (rectangles, pretty much) and will likely fail for real world shapes that have bulges and indents and inclusions etc.

 

Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information. Do not include anything that is unrelated to the issue or question.
Please show the expected outcome based on the sample data you provided.

Need help uploading data? https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.