<?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: How to build an aggregate field on field value group counts? in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-build-an-aggregate-field-on-field-value/m-p/1572554#M86322</link>
    <description>&lt;P&gt;Yes, this is possible, it just requires a bit of Arcade. The first step is creating an AggregateField for each user ID, using an Arcade expression to return 1 if the feature matches the given user type, and 0 if not (this is essentially just going to count the number of users with a given user_id in each cluster):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;new AggregateField({
  name: "SUM_USER_A",
  onStatisticExpression: new ExpressionInfo({
     title: "User A",
     returnType: "number",
     expression: "Number($feature.user_id == 'A')"
  }),
  statisticType: "sum"
})&lt;/LI-CODE&gt;&lt;P&gt;Do this for each user type so that you have a SUM_USER_A, SUM_USER_B, SUM_USER_C, and so on...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, set a cluster renderer using another Arcade expression to Count all the aggregate fields that do not equal zero, and voila! You have the # of user types in each cluster.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fields = [$feature.SUM_USER_A, $feature.SUM_USER_B, $feature.SUM_USER_C];

function isNotZero(value){
  return value != 0;
}
Count(Filter(fields, isNotZero))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example where I did something similar with NYC's boroughs, where the clusters are colored based on the number of boroughs represented by each cluster:&amp;nbsp;&lt;A href="https://codepen.io/annefitz/pen/dPbZVpP?editors=1000" target="_blank"&gt;https://codepen.io/annefitz/pen/dPbZVpP?editors=1000&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 03 Jan 2025 20:42:28 GMT</pubDate>
    <dc:creator>AnneFitz</dc:creator>
    <dc:date>2025-01-03T20:42:28Z</dc:date>
    <item>
      <title>How to build an aggregate field on field value group counts?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-build-an-aggregate-field-on-field-value/m-p/1561237#M86120</link>
      <description>&lt;P&gt;I am building a map representing activities of some users and I would like to be able to clusterise on the number of different users being active on a spécific cluster. My activity features look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;const features = [
 {user_id: "A", activity_id: 1},
 {user_id: "A", activity_id: 2},
 {user_id: "B", activity_id: 3},
 {user_id: "C", activity_id: 4},
 {user_id: "A", activity_id: 5},
]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am using a&amp;nbsp;&lt;SPAN&gt;ClassBreaksRenderer and I would like the color of the cluster to represent the number of unic 'user_id' for the cluster. The cluster count representing all the features above would be 3 (A + B + C).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;AggregateFields with staticType 'count' doesn't allow to pass a groupBy field&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 14:32:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-build-an-aggregate-field-on-field-value/m-p/1561237#M86120</guid>
      <dc:creator>ChristopheDiPrima</dc:creator>
      <dc:date>2024-11-21T14:32:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to build an aggregate field on field value group counts?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-build-an-aggregate-field-on-field-value/m-p/1561240#M86121</link>
      <description>&lt;P&gt;Actulally I would like the number and the size of the cluster to be 5 (5 activities) and the color of the cluster to be defined by&amp;nbsp;&lt;SPAN&gt;some stops following&amp;nbsp;&lt;/SPAN&gt;the number of different "user_id"s&amp;nbsp;&lt;SPAN&gt;(A + B + C = 3). Is this possible?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Nov 2024 14:38:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-build-an-aggregate-field-on-field-value/m-p/1561240#M86121</guid>
      <dc:creator>ChristopheDiPrima</dc:creator>
      <dc:date>2024-11-21T14:38:24Z</dc:date>
    </item>
    <item>
      <title>Re: How to build an aggregate field on field value group counts?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-build-an-aggregate-field-on-field-value/m-p/1572554#M86322</link>
      <description>&lt;P&gt;Yes, this is possible, it just requires a bit of Arcade. The first step is creating an AggregateField for each user ID, using an Arcade expression to return 1 if the feature matches the given user type, and 0 if not (this is essentially just going to count the number of users with a given user_id in each cluster):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;new AggregateField({
  name: "SUM_USER_A",
  onStatisticExpression: new ExpressionInfo({
     title: "User A",
     returnType: "number",
     expression: "Number($feature.user_id == 'A')"
  }),
  statisticType: "sum"
})&lt;/LI-CODE&gt;&lt;P&gt;Do this for each user type so that you have a SUM_USER_A, SUM_USER_B, SUM_USER_C, and so on...&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then, set a cluster renderer using another Arcade expression to Count all the aggregate fields that do not equal zero, and voila! You have the # of user types in each cluster.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fields = [$feature.SUM_USER_A, $feature.SUM_USER_B, $feature.SUM_USER_C];

function isNotZero(value){
  return value != 0;
}
Count(Filter(fields, isNotZero))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's an example where I did something similar with NYC's boroughs, where the clusters are colored based on the number of boroughs represented by each cluster:&amp;nbsp;&lt;A href="https://codepen.io/annefitz/pen/dPbZVpP?editors=1000" target="_blank"&gt;https://codepen.io/annefitz/pen/dPbZVpP?editors=1000&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 20:42:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-build-an-aggregate-field-on-field-value/m-p/1572554#M86322</guid>
      <dc:creator>AnneFitz</dc:creator>
      <dc:date>2025-01-03T20:42:28Z</dc:date>
    </item>
    <item>
      <title>Re: How to build an aggregate field on field value group counts?</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-build-an-aggregate-field-on-field-value/m-p/1572740#M86324</link>
      <description>&lt;P&gt;Works like a charm! Thank you so much! &lt;span class="lia-unicode-emoji" title=":grinning_face:"&gt;😀&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jan 2025 09:25:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/how-to-build-an-aggregate-field-on-field-value/m-p/1572740#M86324</guid>
      <dc:creator>ChristopheDiPrima</dc:creator>
      <dc:date>2025-01-06T09:25:32Z</dc:date>
    </item>
  </channel>
</rss>

