Summarize table in arcade for Popup

377
10
03-05-2021 07:39 AM
Labels (2)
aroininen
New Contributor III

Hello Again folks,

I feel I may be exhausting  my question limit - much appreciation to the community - I am looking into a course.

I'm trying to summarize a field in arcade and get statistics from the  other fields for a result similar to this:

aroininen_0-1614958119661.png

Is this possible in Arcade?

I have looked a Paul Bakers post and the Spanish one and many others but I just can't seem to make anything work

I think Groupby is the option but I just don't know get the sums from the other fields

also do I need to use intersect as I want to get results from the whole dataset if so I can intersect with the municipal border as all developments are within

 

I got this far with this expression (excuse the radon variables!):

aroininen_1-1614958519344.png

var intersectArea = Intersects(FeatureSetByName($map,"Planning_Layers - Development Applications"), $feature)
var treeList = groupBy(intersectArea, "PRStatus",
{name:"count", expression:"PRStatus" , statistic:"COUNT"})

var topFeatures = Top(OrderBy(treeList, "count desc"),10)

var treeList = ''
for (var topFeature in topFeatures) {

treeList += topFeature.PRStatus + " (" + topFeature.count + ")" + TextFormatting.NewLine

}
return treeList

 

Thanks again

Aaron

Tags (3)
0 Kudos
10 Replies
jcarlson
MVP Regular Contributor

You're right, GroupBy is what you want. Since you're just grouping by a single field, and performing basic sums, it's not too complex.

Personally, I find it's easier to create the statistics parameter separately, for the sake of keeping everything straight.

 

var stats_list = [
    { name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
    { name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },
    { name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
    ...
]

GroupBy(intersectArea, "PRStatus", stats_list)

 

 

If you're looking to just return statistics from the entire dataset, there's not really a need to intersect. That being the case, you might adjust your FeatureSetByName function as follows:

 

FeatureSetByName($map,"Planning_Layers - Development Applications", ['field1', 'field2', etc], false)

 

Including a field list tells the script to grab only the fields you need, and setting the includeGeometry parameter to false will improve your script performance a lot by not loading the feature geometry and just working with the attributes separately.

Then just use GroupBy with the featureset directly.

- Josh Carlson
Kendall County GIS
0 Kudos
aroininen
New Contributor III

WOW thanks!!!!

close!!

(FeatureSetByName($map,"Planning_Layers - Development Applications", ['PRStatus', 'Units', 'SingleD'], false)

var stats_list = [
{ name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
{ name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },

{ name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
]

GroupBy("PRStatus", stats_list)

 

Return Stats_list

 

what  did I miss?

aroininen_0-1614961529675.png

 

0 Kudos
jcarlson
MVP Regular Contributor

It should be FeatureSetByName(...), so try taking the parenthesis off of the front. That was a typo in my earlier response.

Also, you'll still need to bring the FeatureSet into the GroupBy function, so assign the featureset to its own variable, then give that variable as the first parameter of GroupBy.

- Josh Carlson
Kendall County GIS
0 Kudos
aroininen
New Contributor III

my apologies

what am I not doing...?

Thanks

 

var planStat = (FeatureSetByName)($map,"Planning_Layers - Development Applications", ['PRStatus', 'Units', 'SingleD'], false)

var stats_list = [
{ name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
{ name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },

{ name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
]

GroupBy(planStat,"PRStatus", stats_list)

 

I get this

Execution Error:h.charAt is not a function

 

 

0 Kudos
jcarlson
MVP Regular Contributor
var planStat = FeatureSetByName($map,"Planning_Layers - Development Applications", ['PRStatus', 'Units', 'SingleD'], false)
- Josh Carlson
Kendall County GIS
0 Kudos
aroininen
New Contributor III

keep getting error

Execution Error:Illegal Value: GroupBy

This is the layer in the map that I am using the expression on: Planning_Layers - Development Applications - Master

should this be something different like the map name...?

var planStat = FeatureSetByName($map,"Planning_Layers - Development Applications - Master", ['PRStatus', 'Units', 'SingleD'], false)

var stats_list = [
{ name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
{ name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },

{ name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
]

GroupBy(planStat,"PRStatus", stats_list)
Return stats_list

 

thanks!!

0 Kudos
aroininen
New Contributor III

I was able to adjust my original expression to no use intersect though!

the one that just returns PLSatus Counts

Thanks!

0 Kudos
jcarlson
MVP Regular Contributor

Make sure that your return is giving you the GroupBy, not the stats_list.

return GroupBy(...)

- Josh Carlson
Kendall County GIS
0 Kudos
aroininen
New Contributor III

Thanks for all your help Josh but I cannot work out this syntax for the return... I will keep trying..

var planStat = FeatureSetByName($map,"Planning_Layers - Development Applications - Master", ['PRStatus', 'Units', 'SingleD'], false)

 

var stats_list = [
{ name: 'Count_PRStatus', expression: 1, statistic: 'COUNT' },
{ name: 'Sum_Units', expression: 'Units', statistic: 'SUM' },

{ name: 'Sum_SingleD', expression: 'SingleD', statistic: 'SUM' },
]


Return GroupBy(planStat,"PRStatus", stats_list);

error Execution Error:Illegal Value: GroupBy

 

or this way - Return; GroupBy(planStat,"PRStatus", stats_list);

gives me this:

aroininen_0-1615046844939.png

 

thanks again Aaron

0 Kudos