<?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 Failed to query Statistics - Attribute rule in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-query-statistics-attribute-rule/m-p/1063760#M41532</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am stuck here. I need to filter a feature set by a date a value. I set up this up but on lie 7 for the "cnt" variable I am getting "Failed to Query statistics", but If I pull out the "AND MMS_Date_Turning &amp;gt;= @current_year" section from my filter it works fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This query fails:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var quad = $feature.Quadrant;

if ($feature.Quadrant != null) {
    var current_year = Date(Year(Now()),0,1)
    var System_valve_set = filter(featuresetbyname($datastore, 'sValve', ['OBJECTID', 'WATERVALVETURNING_STATUS', 'GRID_NUM', 'MMS_Date_Turning'], false), "GRID_NUM = @quad AND MMS_Date_Turning &amp;gt;= @current_year")

    var cnt = count(System_valve_set);

    if (cnt &amp;gt; 0 ) {
        
        var query = "WATERVALVETURNING_STATUS = 'Closed'"
        var System_closed_valve_set = filter(System_valve_set, query)
        var closed_cnt = count(System_closed_valve_set)
        if (closed_cnt &amp;gt; 0){
           
           return count(System_valve_set) - count(System_closed_valve_set)
        }
        else {return count(System_valve_set)}
    }
    else { return null }
}
else { return null }&lt;/LI-CODE&gt;&lt;P&gt;This query works:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var quad = $feature.Quadrant;

if ($feature.Quadrant != null) {
    var current_year = Date(Year(Now()),0,1)
    var System_valve_set = filter(featuresetbyname($datastore, 'sValve', ['OBJECTID', 'WATERVALVETURNING_STATUS', 'GRID_NUM', 'MMS_Date_Turning'], false), "GRID_NUM = @quad")

    var cnt = count(System_valve_set);

    if (cnt &amp;gt; 0 ) {
        
        var query = "WATERVALVETURNING_STATUS = 'Closed'"
        var System_closed_valve_set = filter(System_valve_set, query)
        var closed_cnt = count(System_closed_valve_set)
        if (closed_cnt &amp;gt; 0){
           
           return count(System_valve_set) - count(System_closed_valve_set)
        }
        else {return count(System_valve_set)}
    }
    else { return null }
}
else { return null }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jim&lt;/P&gt;</description>
    <pubDate>Tue, 01 Jun 2021 18:47:59 GMT</pubDate>
    <dc:creator>JimWilliams</dc:creator>
    <dc:date>2021-06-01T18:47:59Z</dc:date>
    <item>
      <title>Failed to query Statistics - Attribute rule</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-query-statistics-attribute-rule/m-p/1063760#M41532</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am stuck here. I need to filter a feature set by a date a value. I set up this up but on lie 7 for the "cnt" variable I am getting "Failed to Query statistics", but If I pull out the "AND MMS_Date_Turning &amp;gt;= @current_year" section from my filter it works fine.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This query fails:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var quad = $feature.Quadrant;

if ($feature.Quadrant != null) {
    var current_year = Date(Year(Now()),0,1)
    var System_valve_set = filter(featuresetbyname($datastore, 'sValve', ['OBJECTID', 'WATERVALVETURNING_STATUS', 'GRID_NUM', 'MMS_Date_Turning'], false), "GRID_NUM = @quad AND MMS_Date_Turning &amp;gt;= @current_year")

    var cnt = count(System_valve_set);

    if (cnt &amp;gt; 0 ) {
        
        var query = "WATERVALVETURNING_STATUS = 'Closed'"
        var System_closed_valve_set = filter(System_valve_set, query)
        var closed_cnt = count(System_closed_valve_set)
        if (closed_cnt &amp;gt; 0){
           
           return count(System_valve_set) - count(System_closed_valve_set)
        }
        else {return count(System_valve_set)}
    }
    else { return null }
}
else { return null }&lt;/LI-CODE&gt;&lt;P&gt;This query works:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var quad = $feature.Quadrant;

if ($feature.Quadrant != null) {
    var current_year = Date(Year(Now()),0,1)
    var System_valve_set = filter(featuresetbyname($datastore, 'sValve', ['OBJECTID', 'WATERVALVETURNING_STATUS', 'GRID_NUM', 'MMS_Date_Turning'], false), "GRID_NUM = @quad")

    var cnt = count(System_valve_set);

    if (cnt &amp;gt; 0 ) {
        
        var query = "WATERVALVETURNING_STATUS = 'Closed'"
        var System_closed_valve_set = filter(System_valve_set, query)
        var closed_cnt = count(System_closed_valve_set)
        if (closed_cnt &amp;gt; 0){
           
           return count(System_valve_set) - count(System_closed_valve_set)
        }
        else {return count(System_valve_set)}
    }
    else { return null }
}
else { return null }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Tue, 01 Jun 2021 18:47:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-query-statistics-attribute-rule/m-p/1063760#M41532</guid>
      <dc:creator>JimWilliams</dc:creator>
      <dc:date>2021-06-01T18:47:59Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to query Statistics - Attribute rule</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-query-statistics-attribute-rule/m-p/1063960#M41547</link>
      <description>&lt;P&gt;Things to try:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// expand the date to include time
var current_year = Date(Year(Now()), 0, 1, 0, 0, 0)

// use text instead
var current_year = Text(Date(Year(Now()), 0, 1), "Y-MM-DD")
var sql = "GRID_NUM = @quad AND MMS_Date_Turning &amp;gt;= date @current_year"

// use the YEAR function in SQL:
var current_year = Year(Now())
var sql = "GRID_NUM = @quad AND YEAR(MMS_Date_Turning) &amp;gt;= @current_year"&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 02 Jun 2021 06:34:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-query-statistics-attribute-rule/m-p/1063960#M41547</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2021-06-02T06:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Failed to query Statistics - Attribute rule</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/failed-to-query-statistics-attribute-rule/m-p/1064185#M41579</link>
      <description>&lt;P&gt;Hey Johannes,&lt;/P&gt;&lt;P&gt;Thanks for the reply super helpful. I am surprised the only option that worked was making the date text. Nothing else seemed to work. Might follow up with ESRI to see if this is a known bug. Below is what worked when filtering with dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var current_year = Text(Date(Year(Now()), 0, 1), "Y-MM-DD")
var sql = "GRID_NUM = @quad AND MMS_Date_Turning &amp;gt;= date @current_year"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Jim&lt;/P&gt;</description>
      <pubDate>Wed, 02 Jun 2021 17:34:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/failed-to-query-statistics-attribute-rule/m-p/1064185#M41579</guid>
      <dc:creator>JimWilliams</dc:creator>
      <dc:date>2021-06-02T17:34:36Z</dc:date>
    </item>
  </channel>
</rss>

