<?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 Data Expression to bin years into groups for Serial Chart in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1330811#M8493</link>
    <description>&lt;P&gt;I'm trying to make a data expression for a serial chart that groups years into categories rather than showing counts for each year. My year field is just stored in an integer field. This is what I've come up with so far but it's not working.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal('https://arcgis.com');
var fs = FeatureSetByPortalItem(
    portal,
    'xxxxxxxxxxxxx',
    0,
    [
        'YearInstall'
    ],
    true
);

var results = [];
for (var i in fs){
    var yearInstall = fs[i].YearInstall;
    var dec = IIf(yearInstall &amp;gt;= 1912 &amp;amp;&amp;amp; yearInstall &amp;lt;= 1961, "1",
           IIf(yearInstall &amp;gt;= 1962 &amp;amp;&amp;amp; yearInstall &amp;lt;= 1991, "2",
           IIf(yearInstall &amp;gt;= 1992 &amp;amp;&amp;amp; yearInstall &amp;lt;= 2023, "3",
           'other')));
    results[i] = dec;
}

return results;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 20 Sep 2023 19:49:26 GMT</pubDate>
    <dc:creator>AustinCanty1</dc:creator>
    <dc:date>2023-09-20T19:49:26Z</dc:date>
    <item>
      <title>Data Expression to bin years into groups for Serial Chart</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1330811#M8493</link>
      <description>&lt;P&gt;I'm trying to make a data expression for a serial chart that groups years into categories rather than showing counts for each year. My year field is just stored in an integer field. This is what I've come up with so far but it's not working.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal('https://arcgis.com');
var fs = FeatureSetByPortalItem(
    portal,
    'xxxxxxxxxxxxx',
    0,
    [
        'YearInstall'
    ],
    true
);

var results = [];
for (var i in fs){
    var yearInstall = fs[i].YearInstall;
    var dec = IIf(yearInstall &amp;gt;= 1912 &amp;amp;&amp;amp; yearInstall &amp;lt;= 1961, "1",
           IIf(yearInstall &amp;gt;= 1962 &amp;amp;&amp;amp; yearInstall &amp;lt;= 1991, "2",
           IIf(yearInstall &amp;gt;= 1992 &amp;amp;&amp;amp; yearInstall &amp;lt;= 2023, "3",
           'other')));
    results[i] = dec;
}

return results;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Sep 2023 19:49:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1330811#M8493</guid>
      <dc:creator>AustinCanty1</dc:creator>
      <dc:date>2023-09-20T19:49:26Z</dc:date>
    </item>
    <item>
      <title>Re: Data Expression to bin years into groups for Serial Chart</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1331008#M8495</link>
      <description>&lt;P&gt;The key thing here is that a Data Expression expects a &lt;STRONG&gt;FeatureSet&lt;/STRONG&gt; as its result, where your expression is returning an array of numeric strings.&lt;/P&gt;&lt;P&gt;If you really wanted to do it this way, you have to build an array of Features and add it to a FeatureSet. You can see a lot of examples here: &lt;A href="https://github.com/Esri/arcade-expressions/tree/master/dashboard_data" target="_blank"&gt;https://github.com/Esri/arcade-expressions/tree/master/dashboard_data&lt;/A&gt;&lt;/P&gt;&lt;P&gt;But really, you can do this all with a function that returns a FeatureSet, like &lt;STRONG&gt;GroupBy&lt;/STRONG&gt;.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByPortalItem(
  Portal('https://arcgis.com'),
  'itemid',
  0,
  ['YearInstall'],
  false
)

var sql = `CASE
WHEN YearInstall &amp;lt; 1962 THEN 1
WHEN YearInstall &amp;lt; 1992 THEN 2
ELSE 3
END`

var grp = GroupBy(
  fs,
  {name: 'year_bin', expression: sql},
  {name: 'total', expression: '1', statistic: "SUM"}
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 13:00:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1331008#M8495</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-09-21T13:00:50Z</dc:date>
    </item>
    <item>
      <title>Re: Data Expression to bin years into groups for Serial Chart</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1331049#M8496</link>
      <description>&lt;P&gt;Wow thanks, Josh!&lt;/P&gt;&lt;P&gt;That seems a lot more efficient, but grp is returning a featureset with just a single row rather than all three. Am I missing something else?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 14:24:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1331049#M8496</guid>
      <dc:creator>AustinCanty1</dc:creator>
      <dc:date>2023-09-21T14:24:12Z</dc:date>
    </item>
    <item>
      <title>Re: Data Expression to bin years into groups for Serial Chart</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1331053#M8497</link>
      <description>&lt;P&gt;What's the actual data table look like?&lt;/P&gt;</description>
      <pubDate>Thu, 21 Sep 2023 14:28:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1331053#M8497</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-09-21T14:28:11Z</dc:date>
    </item>
    <item>
      <title>Re: Data Expression to bin years into groups for Serial Chart</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1331074#M8498</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Year install is an integer that contains some null values. I realize I would have to account for the null values in the function, but that's still only returning one record in the featureset.&lt;/P&gt;&lt;P&gt;I published a copy of the dataset here:&amp;nbsp;&lt;A href="https://www.arcgis.com/home/item.html?id=ad72f530682f4a4a94e65ee996c26bb0#data" target="_self"&gt;https://www.arcgis.com/home/item.html?id=ad72f530682f4a4a94e65ee996c26bb0#data&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 14:20:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1331074#M8498</guid>
      <dc:creator>AustinCanty1</dc:creator>
      <dc:date>2023-09-26T14:20:22Z</dc:date>
    </item>
    <item>
      <title>Re: Data Expression to bin years into groups for Serial Chart</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1332418#M8512</link>
      <description>&lt;P&gt;Accounting for nulls:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = Filter(
  FeatureSetByPortalItem(
    Portal('https://arcgis.com'),
    'ad72f530682f4a4a94e65ee996c26bb0',
    0,
    ['YearInstall'],
    false
  ),
  'YearInstall IS NOT NULL'
)

var sql = `CASE
WHEN YearInstall &amp;lt; 1962 THEN 1
WHEN YearInstall &amp;lt; 1992 THEN 2
ELSE 3
END`

var grp = GroupBy(
  fs,
  {name: 'year_bin', expression: sql},
  {name: 'total', expression: '1', statistic: "SUM"}
)

return grp&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Runs like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1695738281103.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/81639i32F2718AAFE3ED0B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1695738281103.png" alt="jcarlson_0-1695738281103.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I don't see the one-record output. Double check your expression for typos?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 14:25:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1332418#M8512</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2023-09-26T14:25:47Z</dc:date>
    </item>
    <item>
      <title>Re: Data Expression to bin years into groups for Serial Chart</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1332463#M8513</link>
      <description>&lt;P&gt;Thanks again. It works with that sample dataset I provided but not with my actual data.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there something else that needs to be done to use a secured service with stored credentials?&lt;/P&gt;</description>
      <pubDate>Tue, 26 Sep 2023 15:11:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/data-expression-to-bin-years-into-groups-for/m-p/1332463#M8513</guid>
      <dc:creator>AustinCanty1</dc:creator>
      <dc:date>2023-09-26T15:11:47Z</dc:date>
    </item>
  </channel>
</rss>

