<?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 Issues with Arcade... Dictionary to FeatureSet in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/issues-with-arcade-dictionary-to-featureset/m-p/1409895#M58644</link>
    <description>&lt;P&gt;I created an arcade expression that takes a feature service and calculates some stats and outputs the results into a FeatureSet.&lt;/P&gt;&lt;P&gt;The problem that I run into is some of my Dict is not writing to my FeatureSet.&amp;nbsp; When using the Console I can see that everything has written properly to my dictionary but seems to be missing from the FeatureSet.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DJB_0-1713210900948.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/100948iFA2C4C64779BBE55/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DJB_0-1713210900948.png" alt="DJB_0-1713210900948.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DJB_1-1713210962834.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/100949iDF20E29EBD4D4900/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DJB_1-1713210962834.png" alt="DJB_1-1713210962834.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I highlighted the two rows that are missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var Trap_Locations_Tab = FeatureSetByPortalItem(Portal('https://xxxx.arcgis.com/'), '99999999999999999999', 0, ['*'])

var Year_Tab = Distinct(Filter(Trap_Locations_Tab, 'Year IS NOT NULL'), 'Year')

var TrapDict = {'fields': [{'name':'Pests', 'type':'esriFieldTypeString'},
{'name':'Year', 'type':'esriFieldTypeInteger'},
{'name':'Total_Num_Traps', 'type':'esriFieldTypeInteger'},
{'name':'Total_Trap_Checks', 'type':'esriFieldTypeInteger'},
{'name':'Traps_Checked_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Total_Moth_Count_Sum', 'type':'esriFieldTypeInteger'},
{'name':'Moth_Count_Sum_Prior_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Moth_Counts_Sum_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Average_Moth_Count_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Change_Trap_Counts', 'type':'esriFieldTypeInteger'},
{'name':'Moth_Count_Sum_Change', 'type':'esriFieldTypeInteger'}
], 'geometryType': '', 'features': []};

var dt_7 = DateAdd(Date(Max(Trap_Locations_Tab, 'Trap_Check_Date')), -7, 'days')

for (var Y in Year_Tab) {

  var Pest_Tab = Distinct(Filter(Trap_Locations_Tab, 'Year = ' + Y.Year), 'Pest')

  for (var P in Pest_Tab) {

    var PSQL = "Pest = '" + P.Pest + "' And " +  'Year = ' + Y.Year 
    var PrevSQL = "Pest = '" + P.Pest + "' And " +  "Year = " + Y.Year + " And Trap_Check_Date &amp;gt; '" +  dt_7 + "'"
    var PriorSQL = "Pest = '" + P.Pest + "' And " +  "Year = " + Y.Year + " And Trap_Check_Date &amp;lt; '" +  dt_7 + "'"

    var Total_Trap_Cnt = Count(Distinct(Filter(Trap_Locations_Tab, PSQL), 'ParentGlobalID'))
    var Total_Trap_Checks = Count(Filter(Trap_Locations_Tab, PSQL))
    var Trap_Checks_Last_Week = Count(Filter(Trap_Locations_Tab, PrevSQL))

    var Moth_Count_Sum = Sum(Filter(Trap_Locations_Tab, PSQL), 'Counts')
    var Moth_Count_Sum_Prior_Last_Week = Sum(Filter(Trap_Locations_Tab, PriorSQL), 'Counts')
    var Moth_Count_Sum_Last_Week = Sum(Filter(Trap_Locations_Tab, PrevSQL), 'Counts')
    var Moth_Count_Mean_Last_Week = Mean(Filter(Trap_Locations_Tab, PrevSQL), 'Counts')

    Push(TrapDict.features,{
      'attributes': {
        'Pests': Decode(P.Pest, 'WBC', 'Western Bean Cutworm', 'ECB_E', 'European Corn Borer - E (New York Strain)', 'ECB_Z', 'European Corn Borer - Z (Iowa Strain)', 'ECB_H', 'European Corn Borer Hybrid', 'CEW', 'Corn Earworm', 'BCW', 'Black Cutworm', 'TAW', 'True Armyworm', 'FAW', 'Fall Armyworm', 'Other'),//P.Pest,
        'Year': Y.Year,
        'Total_Num_Traps': Total_Trap_Cnt,
        'Total_Trap_Checks': Total_Trap_Checks,
        'Traps_Checked_Last_Week': Trap_Checks_Last_Week,
        'Total_Moth_Count_Sum': Moth_Count_Sum,
        'Moth_Count_Sum_Prior_Last_Week': Moth_Count_Sum_Prior_Last_Week,
        'Moth_Counts_Sum_Last_Week': Moth_Count_Sum_Last_Week,
        'Average_Moth_Count_Last_Week': Moth_Count_Mean_Last_Week}
        })
   
}}
Console(TrapDict)
return FeatureSet(Text(TrapDict)); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the value (CEW) for 2024 that is included falls between the two that are missing... alphabetically (BCW, &lt;STRONG&gt;CEW&lt;/STRONG&gt;, TAW).&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;</description>
    <pubDate>Thu, 18 Apr 2024 19:49:13 GMT</pubDate>
    <dc:creator>DJB</dc:creator>
    <dc:date>2024-04-18T19:49:13Z</dc:date>
    <item>
      <title>Issues with Arcade... Dictionary to FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/issues-with-arcade-dictionary-to-featureset/m-p/1409895#M58644</link>
      <description>&lt;P&gt;I created an arcade expression that takes a feature service and calculates some stats and outputs the results into a FeatureSet.&lt;/P&gt;&lt;P&gt;The problem that I run into is some of my Dict is not writing to my FeatureSet.&amp;nbsp; When using the Console I can see that everything has written properly to my dictionary but seems to be missing from the FeatureSet.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DJB_0-1713210900948.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/100948iFA2C4C64779BBE55/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DJB_0-1713210900948.png" alt="DJB_0-1713210900948.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DJB_1-1713210962834.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/100949iDF20E29EBD4D4900/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DJB_1-1713210962834.png" alt="DJB_1-1713210962834.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I highlighted the two rows that are missing.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var Trap_Locations_Tab = FeatureSetByPortalItem(Portal('https://xxxx.arcgis.com/'), '99999999999999999999', 0, ['*'])

var Year_Tab = Distinct(Filter(Trap_Locations_Tab, 'Year IS NOT NULL'), 'Year')

var TrapDict = {'fields': [{'name':'Pests', 'type':'esriFieldTypeString'},
{'name':'Year', 'type':'esriFieldTypeInteger'},
{'name':'Total_Num_Traps', 'type':'esriFieldTypeInteger'},
{'name':'Total_Trap_Checks', 'type':'esriFieldTypeInteger'},
{'name':'Traps_Checked_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Total_Moth_Count_Sum', 'type':'esriFieldTypeInteger'},
{'name':'Moth_Count_Sum_Prior_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Moth_Counts_Sum_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Average_Moth_Count_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Change_Trap_Counts', 'type':'esriFieldTypeInteger'},
{'name':'Moth_Count_Sum_Change', 'type':'esriFieldTypeInteger'}
], 'geometryType': '', 'features': []};

var dt_7 = DateAdd(Date(Max(Trap_Locations_Tab, 'Trap_Check_Date')), -7, 'days')

for (var Y in Year_Tab) {

  var Pest_Tab = Distinct(Filter(Trap_Locations_Tab, 'Year = ' + Y.Year), 'Pest')

  for (var P in Pest_Tab) {

    var PSQL = "Pest = '" + P.Pest + "' And " +  'Year = ' + Y.Year 
    var PrevSQL = "Pest = '" + P.Pest + "' And " +  "Year = " + Y.Year + " And Trap_Check_Date &amp;gt; '" +  dt_7 + "'"
    var PriorSQL = "Pest = '" + P.Pest + "' And " +  "Year = " + Y.Year + " And Trap_Check_Date &amp;lt; '" +  dt_7 + "'"

    var Total_Trap_Cnt = Count(Distinct(Filter(Trap_Locations_Tab, PSQL), 'ParentGlobalID'))
    var Total_Trap_Checks = Count(Filter(Trap_Locations_Tab, PSQL))
    var Trap_Checks_Last_Week = Count(Filter(Trap_Locations_Tab, PrevSQL))

    var Moth_Count_Sum = Sum(Filter(Trap_Locations_Tab, PSQL), 'Counts')
    var Moth_Count_Sum_Prior_Last_Week = Sum(Filter(Trap_Locations_Tab, PriorSQL), 'Counts')
    var Moth_Count_Sum_Last_Week = Sum(Filter(Trap_Locations_Tab, PrevSQL), 'Counts')
    var Moth_Count_Mean_Last_Week = Mean(Filter(Trap_Locations_Tab, PrevSQL), 'Counts')

    Push(TrapDict.features,{
      'attributes': {
        'Pests': Decode(P.Pest, 'WBC', 'Western Bean Cutworm', 'ECB_E', 'European Corn Borer - E (New York Strain)', 'ECB_Z', 'European Corn Borer - Z (Iowa Strain)', 'ECB_H', 'European Corn Borer Hybrid', 'CEW', 'Corn Earworm', 'BCW', 'Black Cutworm', 'TAW', 'True Armyworm', 'FAW', 'Fall Armyworm', 'Other'),//P.Pest,
        'Year': Y.Year,
        'Total_Num_Traps': Total_Trap_Cnt,
        'Total_Trap_Checks': Total_Trap_Checks,
        'Traps_Checked_Last_Week': Trap_Checks_Last_Week,
        'Total_Moth_Count_Sum': Moth_Count_Sum,
        'Moth_Count_Sum_Prior_Last_Week': Moth_Count_Sum_Prior_Last_Week,
        'Moth_Counts_Sum_Last_Week': Moth_Count_Sum_Last_Week,
        'Average_Moth_Count_Last_Week': Moth_Count_Mean_Last_Week}
        })
   
}}
Console(TrapDict)
return FeatureSet(Text(TrapDict)); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And the value (CEW) for 2024 that is included falls between the two that are missing... alphabetically (BCW, &lt;STRONG&gt;CEW&lt;/STRONG&gt;, TAW).&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;Cheers!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2024 19:49:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/issues-with-arcade-dictionary-to-featureset/m-p/1409895#M58644</guid>
      <dc:creator>DJB</dc:creator>
      <dc:date>2024-04-18T19:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: Issues with Arcade... Dictionary to FeatureSet</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/issues-with-arcade-dictionary-to-featureset/m-p/1411856#M58716</link>
      <description>&lt;P&gt;Well... I think I answered my own question.&amp;nbsp; The issue was around the Date SQL.&amp;nbsp; I was doing my Date calculations from my service as opposed to using a new Date variable &lt;STRONG&gt;Today()&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var dt_7 = DateAdd(Date(Max(Trap_Locations_Tab, 'Trap_Check_Date')), -7, 'days')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As opposed to...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var dt = Today()
var dt_7 = DateAdd(dt, -7, 'days')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need this change detection for my dashboard.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DJB_0-1713469389667.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/101430i6C419C554A797B0A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DJB_0-1713469389667.png" alt="DJB_0-1713469389667.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Here's is my finished code just in case it may help someone else&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var Trap_Locations_Tab = FeatureSetByPortalItem(Portal('XXXXXXXx.arcgis.com/'), '9999999999999999999999999999', 0, ['*'])

var Year_Tab = Distinct(Filter(Trap_Locations_Tab, 'Year IS NOT NULL'), 'Year')

var TrapDict = {'fields': [{'name':'Pests', 'type':'esriFieldTypeString'},
{'name':'Year', 'type':'esriFieldTypeInteger'},
{'name':'Total_Num_Traps', 'type':'esriFieldTypeInteger'},
{'name':'Total_Trap_Checks', 'type':'esriFieldTypeInteger'},
{'name':'Traps_Checked_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Total_Moth_Count_Sum', 'type':'esriFieldTypeInteger'},
{'name':'Moth_Count_Sum_Prior_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Moth_Counts_Sum_Last_Week', 'type':'esriFieldTypeInteger'},
{'name':'Average_Moth_Count_Last_Week', 'type':'esriFieldTypeDouble'},
{'name':'Change_Trap_Counts', 'type':'esriFieldTypeInteger'},
{'name':'Moth_Count_Sum_Change', 'type':'esriFieldTypeInteger'}
], 'geometryType': '', 'features': []};

var dt = Today()
var dt_7 = DateAdd(dt, -7, 'days')

for (var Y in Year_Tab) {

  var Pest_Tab = Distinct(Filter(Trap_Locations_Tab, 'Year = ' + Y.Year), 'Pest')

  for (var P in Pest_Tab) {

    var PSQL = "Pest = '" + P.Pest + "' And " +  'Year = ' + Y.Year 
    var PrevSQL = "Pest = '" + P.Pest + "' And " +  "Year = " + Y.Year + " And Trap_Check_Date &amp;gt; '" +  dt_7 + "'"
    var PriorSQL = "Pest = '" + P.Pest + "' And " +  "Year = " + Y.Year + " And Trap_Check_Date &amp;lt; '" +  dt_7 + "'"

    var Total_Trap_Cnt = Count(Distinct(Filter(Trap_Locations_Tab, PSQL), 'ParentGlobalID'))
    var Total_Trap_Checks = Count(Filter(Trap_Locations_Tab, PSQL))
    var Trap_Checks_Last_Week = Count(Filter(Trap_Locations_Tab, PrevSQL))

    var Moth_Count_Sum = Sum(Filter(Trap_Locations_Tab, PSQL), 'Counts')
    var Moth_Count_Sum_Prior_Last_Week = Sum(Filter(Trap_Locations_Tab, PriorSQL), 'Counts')
    var Moth_Count_Sum_Last_Week = Sum(Filter(Trap_Locations_Tab, PrevSQL), 'Counts')
    var Moth_Count_Mean_Last_Week = Mean(Filter(Trap_Locations_Tab, PrevSQL), 'Counts')

    Push(TrapDict.features,{
      'attributes': {
        'Pests': Decode(P.Pest, 'WBC', 'Western Bean Cutworm', 'ECB_E', 'European Corn Borer - E (New York Strain)', 'ECB_Z', 'European Corn Borer - Z (Iowa Strain)', 'ECB_H', 'European Corn Borer Hybrid', 'CEW', 'Corn Earworm', 'BCW', 'Black Cutworm', 'TAW', 'True Armyworm', 'FAW', 'Fall Armyworm', 'Other'),//P.Pest,
        'Year': Y.Year,
        'Total_Num_Traps': Total_Trap_Cnt,
        'Total_Trap_Checks': Total_Trap_Checks,
        'Traps_Checked_Last_Week': Trap_Checks_Last_Week,
        'Total_Moth_Count_Sum': Moth_Count_Sum,
        'Moth_Count_Sum_Prior_Last_Week': Moth_Count_Sum_Prior_Last_Week,
        'Moth_Counts_Sum_Last_Week': Moth_Count_Sum_Last_Week,
        'Average_Moth_Count_Last_Week': Moth_Count_Mean_Last_Week}
        })
}}

return FeatureSet(Text(TrapDict)); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;~Dan&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2024 19:48:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/issues-with-arcade-dictionary-to-featureset/m-p/1411856#M58716</guid>
      <dc:creator>DJB</dc:creator>
      <dc:date>2024-04-18T19:48:06Z</dc:date>
    </item>
  </channel>
</rss>

