Select to view content in your preferred language

Arcade trouble with GroupBy function

851
1
Jump to solution
06-23-2023 06:54 AM
Labels (3)
clt_cabq
Occasional Contributor III

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
Occasional Contributor III

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

1 Reply
Justin_Greco
Occasional Contributor III

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'}
]
);