<?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: Filter a chart using an expression by the date-range picker in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/filter-a-chart-using-an-expression-by-the-date/m-p/1421812#M9556</link>
    <description>&lt;P&gt;Remember that your chart can do the grouping / counting for you. You don't actually need to use &lt;STRONG&gt;GroupBy&lt;/STRONG&gt; here.&lt;/P&gt;&lt;P&gt;But the real root of the problem is your &lt;STRONG&gt;choicesDict&lt;/STRONG&gt;. You need to include &lt;STRONG&gt;SurveyDate&lt;/STRONG&gt; in the &lt;STRONG&gt;fields&lt;/STRONG&gt; list. Right now you only have &lt;STRONG&gt;split_choices&lt;/STRONG&gt; in your fields, so there is literally no SurveyDate field present in the resulting FeatureSet, regardless of having that attribute present in each of your features. Just add this line to the fields list if choicesDict:&lt;/P&gt;&lt;PRE&gt;{ 'name': 'SurveyDate', 'type': 'esriFiedlTypeDate'}&lt;/PRE&gt;</description>
    <pubDate>Thu, 09 May 2024 12:29:52 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2024-05-09T12:29:52Z</dc:date>
    <item>
      <title>Filter a chart using an expression by the date-range picker</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/filter-a-chart-using-an-expression-by-the-date/m-p/1420701#M9554</link>
      <description>&lt;P&gt;I am attempting to create a Chart using an expression to parse Survey123 data. The raw data is a string that is comma separated, so it is split and grouped by value to get the number of sources per value.&lt;BR /&gt;eg:&lt;BR /&gt;&lt;BR /&gt;"red,blue,green"&lt;BR /&gt;"red,green"&lt;BR /&gt;&lt;BR /&gt;to&lt;BR /&gt;&lt;BR /&gt;red : 2&lt;BR /&gt;blue: 1&lt;BR /&gt;green: 2&lt;BR /&gt;&lt;BR /&gt;The original data also has a survey date. I am using a date picker in the dashboard to filter charts by the date range selected, but since the expression doesn't include a date I can't filter by it.&lt;BR /&gt;&lt;BR /&gt;I've attempted to add the date field to the expressions output, but it only seems to show up if I add the date to the groupby section of my arcade script. The issue there is that the chart then displays a column for each value/date combination&lt;/P&gt;&lt;P&gt;eg:&lt;BR /&gt;red/Date1: 1&lt;BR /&gt;red/Date2: 1&lt;BR /&gt;&lt;BR /&gt;Besides that issue, the picker seems to work. Any ideas on how to get this to work? My first thought was to somehow get the datepicker range as an input to the expression and to filter the values created by the range before output. Is that possible somehow?&lt;BR /&gt;&lt;BR /&gt;I've included the script below: (edited to remove private data)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Reference layer using the FeatureSetByPortalItem() method.
var p = Portal('https://XXXXX.maps.arcgis.com')
var fs = FeatureSetByPortalItem(
p,
'XXXXUIDXXXX',
0,
['Color', 'SurveyDate'],
false
);

// Create empty array for features and feat object
var features = [];
var feat;

// Split comma separated colors and store in dictionary.  
for (var f in fs) { 
    var split_array  =  Sort(Split(f["Color"], ','))

    
    
    var count_arr = Count(split_array) 
    for(var i = 0; i &amp;lt; count_arr; i++ ){ 
        feat = {
            'attributes': {
                'SurveyDate': f["SurveyDate"],
                'split_choices': Proper(Replace(Trim(split_array[i]), '_',' '))
            }
        }
        Push(features, feat);
}}

// Empty dictionary to capture each color reported as separate rows. 
var choicesDict = {
    'fields': [
        { 'name': 'split_choices', 'type': 'esriFieldTypeString'},
      ], 
    'geometryType': '',
    'features': features
}; 

// Convert dictionary to featureSet. 
var fs_dict = FeatureSet(choicesDict); 

// Return featureset after grouping by color. 
return GroupBy(fs_dict, ['split_choices', 'SurveyDate'], 
       [{ name: 'split_count', expression: 'split_choices', statistic: 'COUNT' }]);  // Write an expression that returns a FeatureSet.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 08 May 2024 20:37:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/filter-a-chart-using-an-expression-by-the-date/m-p/1420701#M9554</guid>
      <dc:creator>GregSpiridonov</dc:creator>
      <dc:date>2024-05-08T20:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: Filter a chart using an expression by the date-range picker</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/filter-a-chart-using-an-expression-by-the-date/m-p/1421812#M9556</link>
      <description>&lt;P&gt;Remember that your chart can do the grouping / counting for you. You don't actually need to use &lt;STRONG&gt;GroupBy&lt;/STRONG&gt; here.&lt;/P&gt;&lt;P&gt;But the real root of the problem is your &lt;STRONG&gt;choicesDict&lt;/STRONG&gt;. You need to include &lt;STRONG&gt;SurveyDate&lt;/STRONG&gt; in the &lt;STRONG&gt;fields&lt;/STRONG&gt; list. Right now you only have &lt;STRONG&gt;split_choices&lt;/STRONG&gt; in your fields, so there is literally no SurveyDate field present in the resulting FeatureSet, regardless of having that attribute present in each of your features. Just add this line to the fields list if choicesDict:&lt;/P&gt;&lt;PRE&gt;{ 'name': 'SurveyDate', 'type': 'esriFiedlTypeDate'}&lt;/PRE&gt;</description>
      <pubDate>Thu, 09 May 2024 12:29:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/filter-a-chart-using-an-expression-by-the-date/m-p/1421812#M9556</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-05-09T12:29:52Z</dc:date>
    </item>
  </channel>
</rss>

