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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
mwimberger
Resolver II
Resolver II

Perimeter and Area of Polygon in DAX.

Hi Community

 

I'm trying to figure out if this is even possible in DAX = calculating the area and perimeter of  polygons in DAX .

 

Eventually I would love to see if one can calculate a long axis and minor axis of a polygon, but area and perimeter would be a major win. 

 Here is my test data set:

PolygonOrderX Y

Armada01133.867302 9377.688859
Armada11133.885225 9377.708789
Armada21133.911246 9377.708524
Armada31133.931606 9377.731125
Armada41133.959339 9377.716192
Armada51133.957758 9377.703479
Armada61133.932689 9377.703266
Armada71133.924513 9377.694315
Armada81133.89474 9377.690248
Armada91133.886501 9377.681242
Armada101133.867302 9377.688859
Barbaras01133.940272 9377.685785
Barbaras11133.924513 9377.694315
Barbaras21133.89474 9377.690248
Barbaras31133.886501 9377.681242
Barbaras41133.898729 9377.674412
Barbaras51133.909019 9377.674985
Barbaras61133.940272 9377.685785
Coconuss01133.956245 9377.691305
Coconuss11133.940272 9377.685785
Coconuss21133.924513 9377.694315
Coconuss31133.932689 9377.703266
Coconuss41133.957758 9377.703479
Coconuss51133.956245 9377.691305
Descripta01133.867302 9377.688859
Descripta11133.842369 9377.696331
Descripta21133.869321 9377.753337
Descripta31133.911591 9377.742598
Descripta41133.922642 9377.73665
Descripta51133.931606 9377.731125
Descripta61133.911246 9377.708524
Descripta71133.885225 9377.708789
Descripta81133.867302 9377.688859
Eliptica01133.955761 9378.00986
Eliptica11133.953292 9377.997504
Eliptica21133.932773 9377.974711
Eliptica31133.921109 9377.981121
Eliptica41133.933362 9377.994733
Eliptica51133.931604 9378.002572
Eliptica61133.94595 9378.018399
Eliptica71133.955761 9378.00986

 

 

 

(Order is the vertice number and needs to be in that order) 

 

Or if this is not possible directly in DAX, whether anyone has the skills in doing this in Python during data load in PQ. I'm thinking shapely ? I've tested the below code and it gives the same (very close at least) to what I get from my 3D modelling package

 

 

 

from shapely.geometry import Polygon

coords  = ((-1, 0), (-1, 1), (0, 0.5), (1, 1), (1, 0), (-1, 0))

polygon = Polygon(coords)

polygon.length

 

 

 

And then using polygon.length and polygon.area to give area and perimeter, but I'm not sure how to get this to run through the complete table of polygons and export the list on unique polygons with their respective areas and perimeters through Power Query.

 

thanks heaps in advance for any pointers

 

Cheers

 

Manfred

 

 

 

 

 

1 REPLY 1
v-zhenbw-msft
Community Support
Community Support

Hi @mwimberger ,

 

Sorry for that we just can calculate the length of each point and get the perimeter of polygon.

You can refer the following steps.

 

1. We need to create two calculate columns to get the next row value.

 

x1 = CALCULATE(SUM('Table'[x]),FILTER('Table','Table'[Polygon]=EARLIER('Table'[Polygon]) && 'Table'[Order]=EARLIER('Table'[Order])+1))
y1 = CALCULATE(SUM('Table'[y]),FILTER('Table','Table'[Polygon]=EARLIER('Table'[Polygon]) && 'Table'[Order]=EARLIER('Table'[Order])+1))

 

Per 1.jpg

 

2. Then we can create a new column to get the length of each line.

 

Length = 
var x = POWER([x1]-[x],2)
var y = POWER([y1]-[y],2)
var z = SQRT(x+y)
return
IF(ISBLANK([Column]),BLANK(),   z)

 

Column and Column 2 are the auxiliary column.

 

Per 2.jpg

 

3. At last we can create a table visual, put the polygon name and length in it to get the result like this,

 

per 3.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

Or if you have other better solutions, please share them for more people to see and let us learn from each other.

 

BTW, pbix as attached.

 

Best regards,

 

Community Support Team _ zhenbw

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

November Carousel

Fabric Community Update - November 2024

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.