Finding DISTINCT features using Arcade in List widget in Operations Dashboard

1804
3
03-14-2022 01:03 PM
Labels (1)
LindaSlattery
Occasional Contributor

I am trying to create a list with only distinct features from my table in Operations Dashboard. I am using the following Arcade script:

var provider = Distinct($datapoint["provider_name"])
return {
attributes: {
provider: provider
}
}

In the line item template in the list, I call it using {expression/provider}. I do not get any errors and it results in a provider name being listed, but I do not get unique names. Rather, it lists them all. Any ideas how to correct this?

 

Thanks!

0 Kudos
3 Replies
jcarlson
MVP Esteemed Contributor

The distinct function returns either an array or a FeatureSet, depending on the input.

The expression you have written here is in the dashboard formatting profile of Arcade, which cannot do what you're trying to accomplish. You're telling it to return the distinct values of the provider name of a single datapoint. The function treats this as an array with a single item in it:

jcarlson_0-1647311277878.png

Consider using a Data Expression, similar to this example.

Yours might look like this:

var portal = Portal('https://www.arcgis.com/');

var fs = FeatureSetByPortalItem(
    portal,
    'your itemid',
    0,
    ['provider_name'],
    false
);

return Distinct(fs, 'provider_name') 
- Josh Carlson
Kendall County GIS
EdmundEkanem1
New Contributor

@jcarlson where do we insert this code, still in the advanced formatting? I am trying to do the same thing now. it also seems like the FeatureSetByPortalItem is not active on my end. Please could you any update on this?

0 Kudos
jcarlson
MVP Esteemed Contributor

Nah, follow the link in the original post. Data Expressions are separate data sources; you can create one when you define the data source for a widget.

- Josh Carlson
Kendall County GIS
0 Kudos