Summarize table in arcade for Popup

2343
16
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
16 Replies
aroininen
New Contributor III

Hello Again,

I had a bit of a break though I am able to display total units by Status with this expression!:

Problem is if I keep adding more fields for statistics (i.e Semi, Row)  the result is always the last Groupby

I tried editing the  last statement to add more stats to result but I get nothing

 

here is the expression I am using:

I don't need to order this but if I remove it doesn't work that why I just use top 10

var planstat = FeatureSetByName($map,"Planning_Layers - Development Applications - master", ['PRStatus', 'Units', 'SingleD'], false)
var treeList = groupBy(planstat, "PRStatus",
{name:"count", expression:"PRStatus" , statistic:"COUNT"})
var treeList = groupBy(planstat, "PRStatus",
{name:"count", expression:"Units" , statistic:"SUM"})

 


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

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

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

}
return treeList

If I get this last bit figured out that would be great but I can live with what I have too

Thanks again community!

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

@jcarlson  I have a similar question on OrderBy.  It is showing the total as the first element but with no label.  Then it also does null with no label.  Would be nice if it said Null of course.  But what i want is to not show the total. The help says nothing about a total.  So I figure pop the first element but there is no pop function and Erase will only take array not FeatureSet.  Also Array cannot convert a FeatureSet.

I just want to remove the first one without having to check manually.  I see Top in there but that wont work.

DougBrowning_0-1666210020326.png

 

var plots = Intersects($feature,FeatureSetByName($map,"TerrestrialIndicators", ["RH_BioticIntegrity"], false));
var groupOut = OrderBy(GroupBy(plots, ['RH_BioticIntegrity'], [ { name: 'outputStatName', expression: 'RH_BioticIntegrity', statistic: 'COUNT' } ]),'RH_BioticIntegrity')
var display = ''

for (var grp in groupOut) {
    display = display + grp.RH_BioticIntegrity + " - " + grp.outputStatName + TextFormatting.NewLine 
}
return display

 

 thanks

0 Kudos
jcarlson
MVP Esteemed Contributor

Odd. It shouldn't be including a total if you haven't somehow asked for one...

I'd recommend using your FeatureSet to create an Array, then subset the array to remove the first item and use Concatenate to build a newline-separated string. I wish there were an easy way to get an Array from a FeatureSet.

var out_arr = []

for (var grp in groupOut){
    Push(
        out_arr,
        `${grp.RH_BioticIntegrity} - ${grp.outputStatName}`
    )
}

return Concatenate(
    Slice(out_arr, 1),
    '\n'
)

 

- Josh Carlson
Kendall County GIS
0 Kudos
DougBrowning
MVP Esteemed Contributor

Funny I just posted that "I wish there were an easy way to get an Array from a FeatureSet."  Did you see that one?

But yea I see nothing in the doc that says Order by returns a Total but there it is.

Thanks I will look at it.  For now I just left it in.  Wait just noted that must not be the total.  I dont know what it is number of records??  These are all 16.

DougBrowning_1-1666278032774.png

What the heck is that first number with no label?

thanks

 

 

0 Kudos
jcarlson
MVP Esteemed Contributor

I missed that! Y'know, I thought I had a good handle on Arcade before all this... But then, I couldn't explain anything about how cars work either, even though I know how to drive one.

I'd check the tables of the input layers to make sure you don't have any null records hiding out. Or try throwing some Console functions in to check intermediate outputs.

- Josh Carlson
Kendall County GIS
DougBrowning
MVP Esteemed Contributor

If you look close the second blank number is the Nulls.  I have no idea what the 16 is now.

DougBrowning_0-1666279088153.png

 

0 Kudos
DougBrowning
MVP Esteemed Contributor

I got this working now and added code for Nulls thanks.  Still no idea what the heck the first number is.  Not in the help that I see.  Weird 16 makes no sense.

var plots = Intersects($feature,FeatureSetByName($map,"TerrestrialIndicators", ["RH_HydrologicFunction"], false));
var groupOut = OrderBy(GroupBy(plots, ['RH_HydrologicFunction'], [ { name: 'outputStatName', expression: 'RH_HydrologicFunction', statistic: 'COUNT' } ]),'RH_HydrologicFunction')
var out_arr = []

for (var grp in groupOut){
    if (IsEmpty(grp.RH_HydrologicFunction)) {
         Push(out_arr," Nulls-" + grp.outputStatName)
    }
    else{
    Push(out_arr,grp.RH_HydrologicFunction + "-" + grp.outputStatName)
    }
}

return Concatenate(
    Slice(out_arr, 1),
    ', '
)

DougBrowning_0-1666284867370.png

 

0 Kudos