3

I am familiar with Arcade for pop-ups and labeling, but new to using it for data expressions in the new AGOL dashboards.

I have dataset and I would like to generate dashboard elements based on the concatenation of two fields. E.g. Field_1 has a domain with values 'A', 'B', and 'C', and Field_2 has a domain with values '1' and '2'. I would like to generate charts and other elements that summarize values 'A 1', 'A 2', 'B 1', 'B 2', etc. Due to the nature of the data these fields should remain separate.

Basic concatenation in other aspects of Arcade (pop-ups, labeling, etc), is straightforward:

Concatenate([$feature["Field_1"], $feature["Field_2"]], ' ')

What is the proper workflow for concatenating these fields and summarize for the entire featureset? You call the featureset...

var portal = Portal('https://MyPortal.maps.arcgis.com/');
var itemId = 'itemId';
var layerId = 0;

var fs = FeatureSetByPortalItem(portal, itemId, layerId, ['*'], false);

... and then I'm not sure.

Do you generate a dictionary of potential concatenated values?

It doesn't seem like you can create a new field and calculate values with a featureset, which is what I would do through a GUI.

3

Your Arcade data expression needs to return a FeatureSet for the Dashboard widget to use. Now that you've loaded your item as a FeatureSet, you'll want to:

  1. Iterate over its features
  2. Perform the desired calculation for each feature
  3. Add the resulting value to a dictionary
  4. Turn that dictionary into a FeatureSet
var catDict = {'fields': [{ 'name':'concatenation', 'type':'esriFieldTypeString'}], 'geometryType': '', 'features': []};

var index = 0;

for (feature in fs) {
    var concatenation = Concatenate(feature.field1, feature.field2, ' ');
    catDict.features[index++] = {
        'attributes':{'concatenation':concatenation,
        }
    }
}

var fs_dict = FeatureSet(Text(catDict));

return fs_dict;

I haven't been able to find much clear and concise documentation on using data expressions in Dashboards, but there are some helpful samples in the arcade-expressions repository, which is where all this information was gleaned from.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.