Select to view content in your preferred language

Unable to return distinct count in Arcade data expression

1187
3
Jump to solution
03-08-2023 07:48 AM
Labels (1)
GregKeith
Frequent Contributor

I have an Arcade data expression I'm trying to set as the source for an indicator widget in a dashboard on our Enterprise Portal. This expression should return a count of distinct sites in a hosted feature layer, e.g. 5 distinct sites from 684 records.

The expression below works in the expression editor, returning a Number type of 5, but the Source tab shows an error icon with the message 'Unable to execute Arcade expression'. It seems like this should be a relatively simple expression. All clues and help appreciated, thanks.

Credit to @jcarlson, expression based on answer here. 

 

var ptl = Portal('https://portal_url/')
var fs = FeatureSetByPortalItem(
    ptl,
    'itemid',
    0,
    ['site'],
    false
    );
    
return Count(Distinct(fs, 'site'))

 

 

0 Kudos
1 Solution

Accepted Solutions
jcarlson
MVP Esteemed Contributor

Data expressions need to return a FeatureSet. The Indicator can handle the Count portion, so just return Distinct(fs, 'site'), then configure the widget.

- Josh Carlson
Kendall County GIS

View solution in original post

3 Replies
jcarlson
MVP Esteemed Contributor

Data expressions need to return a FeatureSet. The Indicator can handle the Count portion, so just return Distinct(fs, 'site'), then configure the widget.

- Josh Carlson
Kendall County GIS
GregKeith
Frequent Contributor

Thanks! Works great. Don't know why it worked in the expression editor but not elsewhere, but good enough.

0 Kudos
jcarlson
MVP Esteemed Contributor

Well, the expression editor will return anything so long as the expression is valid. You could have the expression Boolean() and it would return a value. It's when the expression is being loaded by the Dashboard that it looks for the FeatureSet.

Similarly, the Popup editor will return a FeatureSet, but when the popup evaluates the expression, it's looking for something it can render as text or HTML, and a FeatureSet will just show up as [Object object] or something.

- Josh Carlson
Kendall County GIS