Select to view content in your preferred language

Data expression to count attributes across multiple fields using GroupBy

199
0
03-06-2024 08:17 AM
JacobMcDermott
New Contributor

Hello,

I'm relatively new to arcade and have ran into a wall. I've got a layer that has multiple fields named AccessoryStructure1, AccessoryStructure2 and so on all the way to AccessoryStructure10. Each of these fields can then have an attribute from a domain that each field shares. For example a feature in this layer could look something like this:

JacobMcDermott_0-1709740099458.png

The attributes with a letter and number represent a physical structure such as a shed or deck, and 0 means none. What I need to do is get a count of all the various types of structures in the layer so a total of sheds, decks and so on, and then get a count of all the structures combined. My plan was to use the groupby function to pull out each type of structure and count them, set that to a variable, and then create one more variable that is the sum of all the previous variables.

Unfortunately, I'm unable to get the groupby function to work and keep running into errors. Here is my code so far.

var p = Portal('myportalurl')

var fs = FeatureSetByPortalItem(p,'myitem#','7',["AccessoryStructure1",
"AccessoryStructure2","AccessoryStructure3","AccessoryStructure4",
"AccessoryStructure5","AccessoryStructure6","AccessoryStructure7",
"AccessoryStructure8","AccessoryStructure9",
"AccessoryStructure10"], false);

var Shed = GroupBy(
fs,
{name: 'AccessoryStructure', expression: 'Shed'},
[
{name: 'AccessoryStructure1', expression: "case when AccessoryStructure1 = 'S100' then 1 else 0", statistic: 'SUM'},
{name: 'AccessoryStructure2', expression: "case when AccessoryStructure2 = 'S100' then 1 else 0", statistic: 'SUM'},
{name: 'AccessoryStructure3', expression: "case when AccessoryStructure3 = 'S100' then 1 else 0", statistic: 'SUM'},
{name: 'AccessoryStructure4', expression: "case when AccessoryStructure4 = 'S100' then 1 else 0", statistic: 'SUM'},
{name: 'AccessoryStructure5', expression: "case when AccessoryStructure5 = 'S100' then 1 else 0", statistic: 'SUM'},
{name: 'AccessoryStructure6', expression: "case when AccessoryStructure6 = 'S100' then 1 else 0", statistic: 'SUM'},
{name: 'AccessoryStructure7', expression: "case when AccessoryStructure7 = 'S100' then 1 else 0", statistic: 'SUM'},
{name: 'AccessoryStructure8', expression: "case when AccessoryStructure8 = 'S100' then 1 else 0", statistic: 'SUM'},
{name: 'AccessoryStructure9', expression: "case when AccessoryStructure9 = 'S100' then 1 else 0", statistic: 'SUM'},
{name: 'AccessoryStructure10', expression: "case when AccessoryStructure10 = 'S100' then 1 else 0", statistic: 'SUM'}
]
)

return Shed

I then get this error 

 

JacobMcDermott_1-1709741206254.png

I should note that while these values are part of a domain they are the actual code and not the description (so the actual string of text that goes into the attribute field) Not sure if that makes a difference or not but wanted to put that out there.

Here is the domain table if it's helpful to know

JacobMcDermott_2-1709741504637.png

Any help getting me unstuck is appreciated!

Thank you!

0 Kudos
0 Replies