<?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: Arcade Group by Day in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203212#M47437</link>
    <description>&lt;P&gt;Brilliant! I figured it needed something SQL rather than Arcade in the GroupBy. This is just the trick I needed, thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 16 Aug 2022 12:51:27 GMT</pubDate>
    <dc:creator>JasonJordan00</dc:creator>
    <dc:date>2022-08-16T12:51:27Z</dc:date>
    <item>
      <title>Arcade Group by Day</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203058#M47432</link>
      <description>&lt;P&gt;I am trying to come up with a data expression to count how many site visits occurred on each day (using created_date). The normal GroupBy function on the field groups it down to the minute, but I need the day. I've tried doing this but it has no effect. Any ideas?&lt;/P&gt;&lt;P&gt;var daily_visits = GroupBy(fs, [{ name: 'date', expression: Text('created_date','Y-MM-DD')}], [{name: 'total', expression: '1', statistic: 'COUNT'}])&lt;/P&gt;&lt;P&gt;The end goal here is to create a serial chart with cumulative visit numbers over time. I do have a working expressions for that however with the number of records it loads very slowly so I'm trying to group them together before it cycles through and does its counting.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 15 Aug 2022 21:27:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203058#M47432</guid>
      <dc:creator>JasonJordan00</dc:creator>
      <dc:date>2022-08-15T21:27:51Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Group by Day</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203200#M47435</link>
      <description>&lt;P&gt;GroupBy() takes an SQL92 expression, not an Arcade expression.&lt;/P&gt;&lt;P&gt;There are ways to group by day in SQL, but Arcade didn't like any of them, Group By seems to be very limited.&lt;/P&gt;&lt;P&gt;Here's what I came up with in the end:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// load feature set
var fs = FeatureSetByPortalItem(Portal(url), id, layer, ["created_date"], false)

// Convert datetime to date
var fs_date = {
    geometryType: "",
    fields: [
        {name: "DateShort", type: "esriFieldTypeDate"},
        ],
    features: []
}
for(var f in fs) {
    var d = f.created_date
    var date_short = Number(Date(Year(d), Month(d), Day(d)))
    Push(fs_date.features, {attributes: {DateShort: date_short}})
}

// group by and order by DateShort
var fs_grouped_by_date = GroupBy(FeatureSet(Text(fs_date)), "DateShort", {name: "Total", expression: "1", statistic: "COUNT"})
var fs_ordered_by_date = OrderBy(fs_grouped_by_date, "DateShort")

// get cumulative count
var fs_cumulative = {
    geometryType: "",
    fields: [
        {name: "DateShort", type: "esriFieldTypeDate"},
        {name: "Total", type: "esriFieldTypeInteger"},
        {name: "Cumulative", type: "esriFieldTypeInteger"},
        ],
    features: []
}
var cumulative = 0
for(var f in fs_ordered_by_date) {
    cumulative += f.Total
    var new_feature = {attributes: {DateShort: Number(f.DateShort), Total: f.Total, Cumulative: cumulative}}
    Push(fs_cumulative.features, new_feature)
}

// return
return FeatureSet(Text(fs_cumulative))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1660652255523.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/48710i07671110F5895709/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1660652255523.png" alt="JohannesLindner_0-1660652255523.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;It loads reasonably fast for my 4.5k features, your mileage may vary...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you publish from an enterprise gdb, it might be better to do the grouping in a database view with SQL and publish that view.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 12:29:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203200#M47435</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-08-16T12:29:05Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Group by Day</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203212#M47437</link>
      <description>&lt;P&gt;Brilliant! I figured it needed something SQL rather than Arcade in the GroupBy. This is just the trick I needed, thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 12:51:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203212#M47437</guid>
      <dc:creator>JasonJordan00</dc:creator>
      <dc:date>2022-08-16T12:51:27Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Group by Day</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203224#M47439</link>
      <description>&lt;P&gt;Also worth noting, that within the GroupBy SQL statement, you could still do a per-date grouping like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// get featureset
var fs = FeatureSetByPortalItem(
    Portal('your portal url'),
    'itemid of your feature service',
    0, // or whatever layer index you need
    ["created_date"],
    false
)

var fs = FeatureSetByName($datastore,"Building_Footprints")

// group featureset by date
var grouped = GroupBy(
    fs,
    {name: 'datestring', expression: "EXTRACT(YEAR FROM LASTUPDATE) + '-' + EXTRACT(MONTH FROM LASTUPDATE) + '-' + EXTRACT(DAY FROM LASTUPDATE)"},
    {name: 'row_count', expression: '1', statistic: 'COUNT'}
)

// then do whatever else you need with that grouped featureset&lt;/LI-CODE&gt;&lt;P&gt;Any time you can offload something to SQL, you'll benefit from it. Doing another for loop and per-feature build of a FeatureSet will still work, but is comparatively costly. Testing this against a 68k-row layer ran in under a second.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 13:15:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203224#M47439</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-08-16T13:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Group by Day</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203236#M47442</link>
      <description>&lt;P&gt;See, I tried to use the SQL expression, but I tried things like CASTing to Date or using YEAR(created_Date), MONTH, and DAY, and they all failed.&lt;/P&gt;&lt;P&gt;Didn't try EXTRACT. Glad to see that it does work, if you take the right approach.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 13:28:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203236#M47442</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-08-16T13:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Group by Day</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203257#M47447</link>
      <description>&lt;P&gt;Yeah, CAST only works for numbers in Arcade, which is a bit of an inconvenience.&lt;/P&gt;</description>
      <pubDate>Tue, 16 Aug 2022 14:03:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-group-by-day/m-p/1203257#M47447</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-08-16T14:03:56Z</dc:date>
    </item>
  </channel>
</rss>

