<?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: Dashboard filtering indicator data with Expression in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605986#M11008</link>
    <description>&lt;P&gt;Did you change the name of the date field in line 9?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return Filter(fs, `EXTRACT(YEAR from yourDateField) = ${Year(Now())}`)&lt;/LI-CODE&gt;</description>
    <pubDate>Tue, 15 Apr 2025 13:22:29 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2025-04-15T13:22:29Z</dc:date>
    <item>
      <title>Dashboard filtering indicator data with Expression</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605791#M11005</link>
      <description>&lt;P&gt;I'm trying to create a dashboard that dynamically filters data based on specific years but change when a new year rolls around without having to edit the dashboard each year.&amp;nbsp; I thought I had it figured out but cannot seem to get the dashboard to accept the use of my expression within an Indicator widget.&amp;nbsp;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;I have data hosted at AGOL.&amp;nbsp; We have maintenance data in a related table.&amp;nbsp; When maintenance has been performed, a new record gets added to the table with the date.&amp;nbsp; I desire to count the number of times each year maintenance has been performed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;I've confirmed access to the data.&amp;nbsp; Without converting the data to a "FeatureSet" I get the expected value as a result but cannot get the dashboard to accept it as a data source.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've spent more time than I care to admit trying to figure this out including trying AI and cannot seem to get it to work.&amp;nbsp; I'm obviously missing something so I'm here to hopefully gain some knowledge.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Get the current year
var currentYear = Year(Now())

// Set up portal and hosted feature layer
var portal = Portal("MY-URL")

// Load FeatureSet from the portal item
var fs = FeatureSetByPortalItem(
    portal,
    "MyItemID",  // Your portal item ID
    2,                                     // Layer index
    ["Date"],                              // Field to use (ensure "Date" is correct)
    false
)

// Initialize counter
var count = 0

// Loop through features and filter by current year
for (var f in fs) {
    var featureDate = f.Date
    if (!IsEmpty(featureDate)) {
        var featureYear = Left(Text(featureDate), 4)  // Extract year from Date field
        if (featureYear == Text(currentYear)) {
            count += 1  // Increment count for matching year
        }
    }
}

// Optional: If you want to return a FeatureSet with matching features
var resultDict = {
    fields: [
        {name: 'feature_count', type: 'esriFieldTypeInteger'}  // Single field for the count
    ],
    geometryType: '',  // No geometry since you're just counting features
    features: [
        {
            attributes: { feature_count: count }
        }
    ]
}

// Return the count or the filtered FeatureSet
return resultDict  // Or return count if you just need the number&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ArcadeError.jpg" style="width: 911px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/130187i53461BCE7DDA605A/image-size/large?v=v2&amp;amp;px=999" role="button" title="ArcadeError.jpg" alt="ArcadeError.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2025 19:55:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605791#M11005</guid>
      <dc:creator>tschrage</dc:creator>
      <dc:date>2025-04-14T19:55:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard filtering indicator data with Expression</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605816#M11006</link>
      <description>&lt;P&gt;This expression will filter out the records from the current year. The original &lt;A href="https://www.arcgis.com/home/item.html?id=79461a1ec0974301bde274177c7108bd#data" target="_self"&gt;dataset&lt;/A&gt; has 493721 records, with 2550 records for 2025&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com"),
  "79461a1ec0974301bde274177c7108bd", //a layer from the Living Atlas to test 
  0,
  ["place", "mag", "time"],
  false
);

return Filter(fs, `EXTRACT(YEAR from time) = ${Year(Now())}`); //time is the Date field&lt;/LI-CODE&gt;&lt;P&gt;Then, in the Indicator, use the Statistic value type and Count.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Snag_1cd6399.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/130199i9EFB63030FF65D50/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Snag_1cd6399.png" alt="Snag_1cd6399.png" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2025 20:42:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605816#M11006</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-04-14T20:42:54Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard filtering indicator data with Expression</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605834#M11007</link>
      <description>&lt;P&gt;I try that verbatim using my portal information and get the generic error message: &lt;FONT color="#FF0000"&gt;"&lt;/FONT&gt;&lt;SPAN&gt;&lt;FONT color="#FF0000"&gt;Test execution error: Unknown Error. Verify test data."&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;My Date field appears to be formatted exactly like your data.&amp;nbsp; The only difference I can see is mine is located in a related table and yours is part of the base feature.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Apr 2025 21:02:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605834#M11007</guid>
      <dc:creator>tschrage</dc:creator>
      <dc:date>2025-04-14T21:02:40Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard filtering indicator data with Expression</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605986#M11008</link>
      <description>&lt;P&gt;Did you change the name of the date field in line 9?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return Filter(fs, `EXTRACT(YEAR from yourDateField) = ${Year(Now())}`)&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 15 Apr 2025 13:22:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605986#M11008</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2025-04-15T13:22:29Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard filtering indicator data with Expression</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605989#M11009</link>
      <description>&lt;P&gt;&amp;nbsp;I didn't.&amp;nbsp; I guess I didn't understand that Extract function.&amp;nbsp; That worked.&amp;nbsp; Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Apr 2025 13:26:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-filtering-indicator-data-with-expression/m-p/1605989#M11009</guid>
      <dc:creator>tschrage</dc:creator>
      <dc:date>2025-04-15T13:26:52Z</dc:date>
    </item>
  </channel>
</rss>

