<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Determine Count of features with Arcade  to be used in Pop-Up in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/determine-count-of-features-with-arcade-to-be-used/m-p/1271028#M51046</link>
    <description>&lt;P&gt;Your first example doesn't work because &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#groupby" target="_blank" rel="noopener"&gt;GroupBy()&lt;/A&gt; returns a featureset (a collection of features), but the popup expects the expression to return a string value.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You don't need GroupBy() here. You can just use &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#filter" target="_blank" rel="noopener"&gt;Filter()&lt;/A&gt;:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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)&lt;/LI-CODE&gt;</description>
    <pubDate>Thu, 23 Mar 2023 17:56:18 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-03-23T17:56:18Z</dc:date>
    <item>
      <title>Determine Count of features with Arcade  to be used in Pop-Up</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/determine-count-of-features-with-arcade-to-be-used/m-p/1271006#M51043</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I have two point feature layers, one is&amp;nbsp; 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.&amp;nbsp; 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".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;fs&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;FeatureSetByPortalItem&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;Portal&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;'&lt;A href="https://www.arcgis.com" target="_blank" rel="noopener"&gt;https://www.arcgis.com&lt;/A&gt;'&lt;/SPAN&gt;&lt;SPAN&gt;), &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;'ID'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;0&lt;/SPAN&gt;&lt;SPAN&gt;, [&lt;/SPAN&gt;&lt;SPAN&gt;'OFFICIAL_N'&lt;/SPAN&gt;&lt;SPAN&gt;], &lt;/SPAN&gt;&lt;SPAN&gt;False&lt;/SPAN&gt;&lt;SPAN&gt;);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;counts&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;Groupby&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;SPAN&gt;fs&lt;/SPAN&gt;&lt;SPAN&gt;,[&lt;/SPAN&gt;&lt;SPAN&gt;'OFFICIAL_N'&lt;/SPAN&gt;&lt;SPAN&gt;],&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;[{&lt;/SPAN&gt;&lt;SPAN&gt;name&lt;/SPAN&gt;&lt;SPAN&gt;:&lt;/SPAN&gt;&lt;SPAN&gt;'Total'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;SPAN&gt;expression&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;'OFFICIAL_N'&lt;/SPAN&gt;&lt;SPAN&gt;, &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;statistic&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;'COUNT'&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;]);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;return counts&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;Or this code which has an additional for loop but in the pop-up it says that there are 3 features a every site which is incorrect. &lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;fs&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;FeatureSetByPortalItem&lt;/SPAN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&gt;statistic&lt;/SPAN&gt;&lt;SPAN&gt;: &lt;/SPAN&gt;&lt;SPAN&gt;'COUNT'&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;]);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;BR /&gt;&lt;DIV&gt;&lt;SPAN&gt;for&lt;/SPAN&gt;&lt;SPAN&gt; (&lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;item&lt;/SPAN&gt; &lt;SPAN&gt;in&lt;/SPAN&gt; &lt;SPAN&gt;counts&lt;/SPAN&gt;&lt;SPAN&gt;){&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; &lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;totalcount&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;item&lt;/SPAN&gt;&lt;SPAN&gt;[&lt;/SPAN&gt;&lt;SPAN&gt;'Total'&lt;/SPAN&gt;&lt;SPAN&gt;]&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;var&lt;/SPAN&gt; &lt;SPAN&gt;result&lt;/SPAN&gt;&lt;SPAN&gt; = &lt;/SPAN&gt;&lt;SPAN&gt;TextFormatting&lt;/SPAN&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;SPAN&gt;NewLine&lt;/SPAN&gt;&lt;SPAN&gt; + &lt;/SPAN&gt;&lt;SPAN&gt;'Total Number of Features at Mine Site: '&lt;/SPAN&gt;&lt;SPAN&gt; + &lt;/SPAN&gt;&lt;SPAN&gt;totalcount&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;return&lt;/SPAN&gt; &lt;SPAN&gt;result&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;I know I am probably missing something somewhere in the code but can't figure it out so any help would be greatly appreciated as I am new to Arcade!&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 23 Mar 2023 17:39:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/determine-count-of-features-with-arcade-to-be-used/m-p/1271006#M51043</guid>
      <dc:creator>JeremyMcDonald1</dc:creator>
      <dc:date>2023-03-23T17:39:35Z</dc:date>
    </item>
    <item>
      <title>Re: Determine Count of features with Arcade  to be used in Pop-Up</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/determine-count-of-features-with-arcade-to-be-used/m-p/1271028#M51046</link>
      <description>&lt;P&gt;Your first example doesn't work because &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#groupby" target="_blank" rel="noopener"&gt;GroupBy()&lt;/A&gt; returns a featureset (a collection of features), but the popup expects the expression to return a string value.&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You don't need GroupBy() here. You can just use &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#filter" target="_blank" rel="noopener"&gt;Filter()&lt;/A&gt;:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;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)&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 23 Mar 2023 17:56:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/determine-count-of-features-with-arcade-to-be-used/m-p/1271028#M51046</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-03-23T17:56:18Z</dc:date>
    </item>
    <item>
      <title>Re: Determine Count of features with Arcade  to be used in Pop-Up</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/determine-count-of-features-with-arcade-to-be-used/m-p/1276415#M51336</link>
      <description>&lt;LI-CODE lang="python"&gt;// 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 &amp;amp;&amp;amp; Within($feature.SHAPE, Geometry($feature)));

// Return the count of matching Mine Features
return Count(matchingMineFeatures);&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 06 Apr 2023 22:50:04 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/determine-count-of-features-with-arcade-to-be-used/m-p/1276415#M51336</guid>
      <dc:creator>avonmoos</dc:creator>
      <dc:date>2023-04-06T22:50:04Z</dc:date>
    </item>
  </channel>
</rss>

