Select to view content in your preferred language

Calculating an Arcade Expression from Two Different Feature Layers

980
2
01-04-2022 07:09 AM
Labels (1)
Dylan_Wingler
New Contributor II

Hello All,

I'm trying to calculate the percent change in population between different hosted feature layers in a web map for a dashboard indicator. I am unfamiliar with Arcade but below is what I have pieced together so far.

 

var starYear = FeatureSetByName($map, 'Census City Blocks 2020')
var tenYear = FeatureSetByName($map,'Census City Blocks 2010')

var tenYearPop = {'fields': [{'name': 'Total_Pop', 'type': 'esriFieldTypeInteger'}], 
                    'geometryType': '', 'features': []}; 

var todayPop = {'fields': [{'name': 'Total_Pop', 'type': 'esriFieldTypeInteger'}], 
                    'geometryType': '', 'features': []};

var tenYearChange = round(((todayPop-tenYearPop)/todayPop)*100, 2) +'%'
return tenYearChange

 

 

The result of the code above is shown below.

Arcade.png

 

The result should be 5.98%. The field name for the population for both feature layers is Total_Pop. Any idea on how to calculate this?

0 Kudos
2 Replies
jcarlson
MVP Esteemed Contributor

Those variables todayPop and tenYearPop are just dictionaries with nothing in their features array. So for one thing, they're not FeatureSets, and for another, there's literally nothing in them to calculate values for. You need some way of either populating those and converting them to actual FeatureSets, or else you need to perform the calculation against the starYear and tenYear FeatureSets you've already brought in.

Another thing: in a dashboard data expression, you can't reference the $map, you've got to use the FeatureSetByPortalItem function to bring in any layers you're working with.

If you're unfamiliar with Arcade, it can seem like quite a lot, but check out some of the sample dashboard expressions to get you started.

- Josh Carlson
Kendall County GIS
Dylan_Wingler
New Contributor II

Can FeatureSetByPortalItem use ArcGIS Online hosted feature layers?

0 Kudos