Select to view content in your preferred language

Looking for help with creating a dashboard element that uses multiple layers to calculate a total count of data points

151
1
08-06-2024 07:35 AM
Frank_Herrick
New Contributor

Looking for help with creating a dashboard element that uses multiple layers to calculate a total count of data points. For context, we have a web map on ArcGIS Online being used for data collection with field maps. It consists of several layers related to different pieces of infrastructure being updated. The attributes of the layers themselves can't be altered so unfortunately creating a new calculated field or joins between the layers isn't a possibility. We are currently monitoring the progress of these updates through a simple dashboard that uses the indicator to show a count of each layer type being updated. While this is serviceable for the time being, it creates unneeded clutter in the dashboard as we are less concerned about individual counts and instead the total count of updates. We'd rather have something more akin to a summary that's easy to glace at rather than layer specific information.

 

From what I can tell, I think we'd have to utilize arcade functionality in the dashboard indicator alongside "FeatureSet", but my arcade knowledge is limited at best. Any guidance would be greatly appreciated.

1 Reply
NicoleJohnson
Occasional Contributor

You're on the right track with Arcade and specifically FeatureSets. Basically, each layer you're wanting to get a count from will be its own FeatureSet which you can get a count from, then you add those values and put them in a new FeatureSet.

Something like the following:

 

// I'm getting my data from an enterprise portal, you may want to do something different by exploring the other FeatureSet options.
var p = Portal('https://somewebsite.com/portal')

// Make sure to read the documentation for whichever FeatureSetBy option you choose. I'm being lazy here and just grabbing all fields, but good practice is to only request the ones you actually need.
var orgsFS = FeatureSetByPortalItem(p, 'itemID', 0, ['*'], false)
var contactsFS = FeatureSetByPortalItem(p, 'itemID', 1, ['*'], false)
var commsFS = FeatureSetByPortalItem(p, 'itemID', 2, ['*'], false)

var tempTotal = Count(orgsFS) + Count(contactsFS) + Count(commsFS)

// Create an empty dictionary to load tempTotal into
var dict = {
  fields: [
    {name: 'total', type: 'esriFieldTypeInteger'}
  ], geometryType: '', features: []
}

// Load tempTotal into the dictionary
Push(dict['features'], {attributes: {total: tempTotal}})

var totalFS = FeatureSet(Text(dict))

// This gives you access to the new FeatureSet (and its fields) on the "Data" tab of the indicator. To get the total, choose Statistic: Sum and Field: total.
return totalFS

 

I initially tried to just add the three counts together, and despite returning the correct number in the Arcade editor, once I exited the editor, I got a warning symbol on the "Select a layer" page saying, "Unable to execute Arcade script." This is because in the data expression, you are wanting to create data, not just a value, if that makes sense?