Select to view content in your preferred language

Arcade trouble with GroupBy function

1597
3
Jump to solution
06-23-2023 06:54 AM
clt_cabq
Frequent Contributor

I have a layer of locations with a related table that contains 'calls for service' to a given location by police, fire, or code enforcement staff. I want to include in the pop up a breakdown of the types of alls made to each location, including the number of each unique type and a summary of a points score applied to each call based on the severity of the call type (for instance homicides get a 10, wiring infractions a 1). I think I can do this using a combination of the GroupBy function and FeatureSetByRelationshipName function. However, I keep running into a problem with the GroupBy syntax where Arcade flags the GroupBy statement and says it is an invalid variable assignment. I've modeled this after examples provided and can't figure out what i am missing in my code which is below. Any thoughts?

 
var CallsByType = GroupBy(FeatureSetByRelationshipName($feature, "AdaptLocationCallDetails"),
[
  {name:'Department', expression:'BU_SOURCE'}
  {name:'Type' , expression:'CALLDESCRIPTION'}
],
[
  {name:'Total',expression:'1',statistic:'COUNT'}
  {name:'Points',expression:'POINTVALUE',statistic:'SUM'}
]
);

0 Kudos
1 Solution

Accepted Solutions
Justin_Greco
Frequent Contributor

The first thing that catches my eye is that you don't have commas separating the objects in the arrays.  Also if this is the only line of your expression, make sure to return CallsByType (or don't even declare the variable).

 

var CallsByType = GroupBy(FeatureSetByRelationshipName($feature, "AdaptLocationCallDetails"),
[
  {name:'Department', expression:'BU_SOURCE'},
  {name:'Type' , expression:'CALLDESCRIPTION'}
],
[
  {name:'Total',expression:'1',statistic:'COUNT'},
  {name:'Points',expression:'POINTVALUE',statistic:'SUM'}
]
);

 

View solution in original post

3 Replies
Justin_Greco
Frequent Contributor

The first thing that catches my eye is that you don't have commas separating the objects in the arrays.  Also if this is the only line of your expression, make sure to return CallsByType (or don't even declare the variable).

 

var CallsByType = GroupBy(FeatureSetByRelationshipName($feature, "AdaptLocationCallDetails"),
[
  {name:'Department', expression:'BU_SOURCE'},
  {name:'Type' , expression:'CALLDESCRIPTION'}
],
[
  {name:'Total',expression:'1',statistic:'COUNT'},
  {name:'Points',expression:'POINTVALUE',statistic:'SUM'}
]
);

 

dcaESRIwvges
Emerging Contributor

I'm so glad i found this! I can't find a description of what is required for the GroupByFields and Statistics part of this function. I know name: in the first section is the field name, but what is the expression: in the first section and and what does the "name:" refer to in the last section or statistics? is this arbitrary? why is it expression: '1' and 'POINTVALUE', The ESRI help only gives some bad examples but doesn't explain the parts of the function. https://developers.arcgis.com/arcade/function-reference/featureset_functions/#groupby

0 Kudos
dcaESRIwvges
Emerging Contributor

nevermind, I found the descirptions below.

0 Kudos