Select to view content in your preferred language

Display sum of lengths by diameter using arcade in dashboards

183
2
03-25-2025 04:12 PM
Labels (1)
LivDurica
New Contributor

Hello, I am new to arcade and have been having some trouble with creating a table. This is my first post, as well, so if I’m missing something or going about this the wrong way, let me know. I have line features that contain fields for diameter and length. I want to create a table that sums up the length by diameter. For example, the total length of pipes with a 4 inch diameter is 2,000 ft. I’d like to write code that creates a table with all of the diameters on the left and the sum of the pipe lengths for that diameter on the right. 

I haven’t been able to find similar cases like this online and I feel like I’ve just hit a wall. I tried a script that an AI suggested, but have just been getting vague syntax errors when attempting. Does the code that it suggests make sense? 

0 Kudos
2 Replies
KenBuja
MVP Esteemed Contributor

When asking a question about code, please the code editor instead of a image of the code.

You can use the GroupBy function to do this type of summary. You code would look something like this

var fs = FeatureSetByPortalItem(Portal("your portal"), "itemId", 0, ["PipeDiameterField", "PipeLengthField"], false);

GroupBy(fs, ["PipeDiameterField"], { name: "Length", expression: "PipeLengthField", statistic: "SUM" })

 

0 Kudos
RhettZufelt
MVP Notable Contributor

That function is built into the Table elements in ArcGIS Online dashboards without any code.

RhettZufelt_0-1743198076765.png

Just select the Grouped values, set the field you want to group by as the Category field, choose "Sum" and the value/sort fields.

R_

 

0 Kudos