<?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: Counting query results in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/counting-query-results/m-p/1132057#M75858</link>
    <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/542369"&gt;@AnthonyDAlessio&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure if I understand the problem correctly. What I understand is: You want to filter a FeatureLayer with the&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#definitionExpression" target="_blank" rel="noopener"&gt;definitionExpression&lt;/A&gt;&amp;nbsp;and after each filtering query, you want to know how many features of each category are being shown. And in order to get this information you use the&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-smartMapping-statistics-uniqueValues.html" target="_blank" rel="noopener"&gt;uniqueValues&lt;/A&gt; function. Is this correct?&lt;/P&gt;&lt;P&gt;Can you maybe provide some code snippet in order for us to better understand the issue at hand?&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
    <pubDate>Mon, 10 Jan 2022 16:10:12 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2022-01-10T16:10:12Z</dc:date>
    <item>
      <title>Counting query results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/counting-query-results/m-p/1131716#M75845</link>
      <description>&lt;P&gt;I have a query that runs against a Feature layer to returns points in a SceneView&amp;nbsp; via a DefinitionExpression (just saw, maybe deprecated, will look into that, but it works just fine)&lt;/P&gt;&lt;P&gt;These points could be one of 100 or so different categories and I'm trying to show how many of each category were returned.&amp;nbsp; I have the initial count for each one using uniqueValues, but that works because at the start every item in every category is displayed.&lt;/P&gt;&lt;P&gt;Category1 (7)&lt;/P&gt;&lt;P&gt;Category2 (15)&lt;/P&gt;&lt;P&gt;Category3 (10)&lt;/P&gt;&lt;P&gt;After the filter is run, maybe Category1 only has 5 items now, Category2 has 10, etc.&lt;/P&gt;&lt;P&gt;If ArcGIS was a database I'd probably just query the fields I needed to calculate this when I initially pull in the data, store it in an array and just query that array to get my counts when things were updated so I wouldn't have to go back to the database, but ArcGIS doesn't let me do a straight up select statement that I'm aware of.&lt;/P&gt;&lt;P&gt;I'm looking for advice on how best to update these counts after a query is run, I can figure out how many total points were returned, but I need to be able to display how many in each category were returned from the query.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Jan 2022 20:35:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/counting-query-results/m-p/1131716#M75845</guid>
      <dc:creator>AnthonyDAlessio</dc:creator>
      <dc:date>2022-01-07T20:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Counting query results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/counting-query-results/m-p/1132057#M75858</link>
      <description>&lt;P&gt;Hi &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/542369"&gt;@AnthonyDAlessio&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am not sure if I understand the problem correctly. What I understand is: You want to filter a FeatureLayer with the&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#definitionExpression" target="_blank" rel="noopener"&gt;definitionExpression&lt;/A&gt;&amp;nbsp;and after each filtering query, you want to know how many features of each category are being shown. And in order to get this information you use the&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-smartMapping-statistics-uniqueValues.html" target="_blank" rel="noopener"&gt;uniqueValues&lt;/A&gt; function. Is this correct?&lt;/P&gt;&lt;P&gt;Can you maybe provide some code snippet in order for us to better understand the issue at hand?&lt;/P&gt;&lt;P&gt;Daniel&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jan 2022 16:10:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/counting-query-results/m-p/1132057#M75858</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-10T16:10:12Z</dc:date>
    </item>
    <item>
      <title>Re: Counting query results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/counting-query-results/m-p/1132163#M75860</link>
      <description>&lt;P&gt;Thanks Daniel, that pretty much sums it up, (included a picture of the checkboxes I'm using to drive the filter) three categories across the top and 100 or so different indications.&amp;nbsp; When you check/uncheck one of the 3 boxes across the top I filter the sites shown using Layer.definitionExpression.&amp;nbsp; &amp;nbsp;All this works well, but I'm trying to get a new count of how many sites perform that "Indication" to update the labels, for example: as you can see in the image there is 1 site that does "Acute Kidney Injury", if that site only happens to be "Pre-Clinical" and I deselect "Pre-Clinical" then after the filter runs I want to show (0) next to the label instead of (1)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screenshot 2022-01-10 143607.png" style="width: 346px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31128i038023A31F9911A4/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screenshot 2022-01-10 143607.png" alt="Screenshot 2022-01-10 143607.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;As I said, normally I'd just query the database directly and build an array of these to easily change the values as checkboxes are changed, no way to do this in ArcGIS that I have found (I could definitely be missing something though)&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;SELECT&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;COUNT&lt;/SPAN&gt;&lt;SPAN&gt;(&lt;/SPAN&gt;&lt;EM&gt;column_name&lt;/EM&gt;&lt;SPAN&gt;)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;FROM&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;table_name&lt;/EM&gt;&lt;BR /&gt;&lt;SPAN class=""&gt;WHERE&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;EM&gt;condition&lt;/EM&gt;&lt;SPAN&gt;;&lt;/SPAN&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Here is the uniqueValues code used to build the checkboxes and initially come up with the total.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;uniqueValues({
  layer: conditionLayer,
  field: "Indication",

  view: map
  }).then(function (response) {
    // prints each unique value and the count of features containing that value
    this.infos = response.uniqueValueInfos;
    $.each(this.infos, function () {
      var currentValue = this.value;
        $("#feature-node").append('&amp;lt;input type="checkbox" id="' + currentValue +'" name="checkbox" checked="true" value="'+ currentValue + '" onClick="filter()"&amp;gt;').append('&amp;lt;label for="' + currentValue +'""&amp;gt;' + currentValue + ' (' + this.count + ')&amp;lt;/label&amp;gt;&amp;lt;/div&amp;gt;&amp;lt;BR&amp;gt;');
        });
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Jan 2022 19:59:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/counting-query-results/m-p/1132163#M75860</guid>
      <dc:creator>AnthonyDAlessio</dc:creator>
      <dc:date>2022-01-10T19:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Counting query results</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/counting-query-results/m-p/1132406#M75863</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/542369"&gt;@AnthonyDAlessio&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for providing details about the issue! I think I now understand your problem.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the easiest solution would be to put the code snippet which you provided into a function and then call that function right after each change of the definitionExpression (or use the &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-core-Accessor.html#watch" target="_blank" rel="noopener"&gt;watch()&lt;/A&gt; function of the featureLayer in order to listen to a change of the definitonExpression). The &lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-smartMapping-statistics-uniqueValues.html" target="_blank" rel="noopener"&gt;uniqueValues&lt;/A&gt; function adapts the results according to the definitionExpression. Maybe you will need to adjust the code a bit to not always re-generate the checkboxes but just change the count value.&amp;nbsp;&lt;/P&gt;&lt;P&gt;And on the side: It is possible to query all features of a featureLayer with a WHERE clause. You can use the&amp;nbsp;&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#createQuery" target="_blank" rel="noopener"&gt;layer.createQuery()&lt;/A&gt;&amp;nbsp;or layer.&lt;A href="https://developers.arcgis.com/javascript/latest/api-reference/esri-layers-FeatureLayer.html#queryFeatures" target="_blank" rel="noopener"&gt;queryFeatures()&lt;/A&gt; function.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I hope this helps, if you have further questions just ask &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Daniel&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Jan 2022 12:55:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/counting-query-results/m-p/1132406#M75863</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-01-11T12:55:00Z</dc:date>
    </item>
  </channel>
</rss>

