I have two point feature layers, one is for Mine Sites and the second is for Mine Features. What I want to do is write an arcade expression to be used in the pop-up which displays the count of Mine Features for each Mine Site. They do not have a relate to connect them but I assumed it would be possible to pull the data through FeatureSetByPortalItem. Both feature layers contain the matching fields such as "OFFICIAL_N".
I have it written two ways but I'm sure I'm missing a step somewhere to make it work in the pop-up. As neither are giving me the result I want.
This option gives me the counts based on the Official Name which is the same between both feature layers. but when I try to use this expression in the pop-up it returns [object Object] instead of the numbered Counts. But when I run it in the Arcade Window it does give me the total counts for each Name.
Your first example doesn't work because GroupBy() returns a featureset (a collection of features), but the popup expects the expression to return a string value.
Your second example doesn't work because you keep overwriting the result variable in your for loop. So the returned value will always be the count of the last mine site.
You don't need GroupBy() here. You can just use Filter():
var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), 'ID', 0, ['OFFICIAL_N'], False) var offilical_n = $feature.OFFICIAL_N var mine_features_at_this_site = Filter(fs, "OFFICIAL_N = @official_n") return Count(mine_features_at_this_site)
// Get all Mine Features var allMineFeatures = FeatureSetByPortalItem(Portal('portal-id'), 'item-id', 0, ['OFFICIAL_N', 'SHAPE']); // Get matching Mine Features for the current Mine Site var matchingMineFeatures = Filter(allMineFeatures, $feature.OFFICIAL_N == $feature.OFFICIAL_N && Within($feature.SHAPE, Geometry($feature))); // Return the count of matching Mine Features return Count(matchingMineFeatures);