<?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: Custom Arcade Data source returns fewer records than it gets in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1541043#M10309</link>
    <description>&lt;P&gt;With some more testing, I found a way to get the result faster, using the GroupBy function. Give this a try&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portalItem = "RanDOmP0rta1iDNUm85r";
var thisPortal = Portal("https://myserver.mydomain.com/portal");
var inspections = FeatureSetByPortalItem(
  thisPortal,
  portalItem,
  58,
  ["InspectionId", "PrjStartDate", "ShopDescription", "DistrictDescription"]
);

GroupBy(
  inspections,
  "OBJECTID",
  [
    { name: "InspectionID", expression: "1", statistic: "MAX" },
    { name: "ShopDescription", expression: "1", statistic: "MAX" },
    { name: "District", expression: "DistrictDescription", statistic: "MAX" },
    {
      name: "CycleYear",
      expression: "MOD(EXTRACT(YEAR FROM PrjStartDate), 5) + 1",
      statistic: "MAX"
    }
  ]
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 20 Sep 2024 20:05:03 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2024-09-20T20:05:03Z</dc:date>
    <item>
      <title>Custom Arcade Data source returns fewer records than it gets</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1540976#M10306</link>
      <description>&lt;P&gt;I'm having trouble with an Arcade data source that I want to use in a dashboard (Enterprise 11.1). The goal is to take some inspections in Cityworks and sort them into bins based on what year in a 5-year cycle they fall in, to help managers rebalance them.&lt;/P&gt;&lt;P&gt;The problem is, the expression returns fewer values than it pulls in initially. Even more perplexing, the exact number of records returned each time is different:&lt;/P&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="JCGuarneri_0-1726849457682.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115579i8A8F5969521B3E4D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JCGuarneri_0-1726849457682.png" alt="JCGuarneri_0-1726849457682.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JCGuarneri_1-1726849730158.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115580iE89DD19FE167573A/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JCGuarneri_1-1726849730158.png" alt="JCGuarneri_1-1726849730158.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code I'm using (server names changed to protect the innocent). Is there something I'm missing in the code that could cause that?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portalItem = 'RanDOmP0rta1iDNUm85r';
var thisPortal = Portal('https://myserver.mydomain.com/portal');
var inspections = FeatureSetByPortalItem(thisPortal, portalItem, 58,['InspectionId','PrjStartDate','ShopDescription','DistrictDescription']);

//create dict to store updated features
var cycleYears = {
  'fields': [{'name':'InspectionID', 'type': 'esriFieldTypeOID'},
      {'name':'ShopDescription', 'type': 'esriFieldTypeString'},
      {'name':'District', 'type': 'esriFieldTypeString'},
      {'name':'CycleYear','type': 'esriFieldTypeDouble'}],
  'geometryType': '',
  'features': []
}
var count1 = Count(inspections);
console(`Records in: ${count1}`);

//put the year in each record into a bin
//append to dict
for(var f in inspections) {
  var cycleYear = (Year(f.PrjStartDate) % 5) +1;
  var new_f = {'attributes': {'InspectionID':f.InspectionID,
        //'PrjStartDate':f.PrjStartDate,
        'ShopDescription':f.ShopDescription,
        //'Text1': f.Text1,
        'District': f.DistrictDescription,
        'CycleYear': cycleYear
  }}
  Push(cycleYears.features, new_f)
}

//convert to feature set and output as data source
var inspCounts = FeatureSet(Text(cycleYears));
var count2 = Count(inspCounts)
console(`Records out: ${count2}`);
return inspCounts;

&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 16:30:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1540976#M10306</guid>
      <dc:creator>JCGuarneri</dc:creator>
      <dc:date>2024-09-20T16:30:50Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Arcade Data source returns fewer records than it gets</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1540998#M10307</link>
      <description>&lt;P&gt;It's because you set the InspectionID field in the dictionary as an esriFieldTypeOID. In testing with my data, if I use an InspectionID field that has unique values, I get the correct number of records. If I use a field without unique records, it only returns the number of unique records. Changing the field type to esriFieldTypeInteger returns all the records, regardless of whether the value are unique or not.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var cycleYears = {
  'fields': [{'name':'InspectionID', 'type': 'esriFieldTypeInteger'},
      {'name':'ShopDescription', 'type': 'esriFieldTypeString'},
      {'name':'District', 'type': 'esriFieldTypeString'},
      {'name':'CycleYear','type': 'esriFieldTypeDouble'}],
  'geometryType': '',
  'features': []
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 17:13:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1540998#M10307</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-09-20T17:13:49Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Arcade Data source returns fewer records than it gets</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1541001#M10308</link>
      <description>&lt;P&gt;Ah, that worked! Thank you. Theoretically, those are all unique. But I'm happy that works. Exposed another thing I need to sort out, but this get's me very close to the finish line.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 17:31:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1541001#M10308</guid>
      <dc:creator>JCGuarneri</dc:creator>
      <dc:date>2024-09-20T17:31:19Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Arcade Data source returns fewer records than it gets</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1541043#M10309</link>
      <description>&lt;P&gt;With some more testing, I found a way to get the result faster, using the GroupBy function. Give this a try&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portalItem = "RanDOmP0rta1iDNUm85r";
var thisPortal = Portal("https://myserver.mydomain.com/portal");
var inspections = FeatureSetByPortalItem(
  thisPortal,
  portalItem,
  58,
  ["InspectionId", "PrjStartDate", "ShopDescription", "DistrictDescription"]
);

GroupBy(
  inspections,
  "OBJECTID",
  [
    { name: "InspectionID", expression: "1", statistic: "MAX" },
    { name: "ShopDescription", expression: "1", statistic: "MAX" },
    { name: "District", expression: "DistrictDescription", statistic: "MAX" },
    {
      name: "CycleYear",
      expression: "MOD(EXTRACT(YEAR FROM PrjStartDate), 5) + 1",
      statistic: "MAX"
    }
  ]
);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 20:05:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1541043#M10309</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-09-20T20:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Custom Arcade Data source returns fewer records than it gets</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1541056#M10311</link>
      <description>&lt;P&gt;You're not kidding about that being faster! I had to make a couple minor modifications, but it is returning the correct number of values for each cycle year. I can't seem to get it to populate values correctly for ShopDescription and District (returns NaN), but I was considering splitting out those categories at the Cityworks URL side, anyway.&lt;/P&gt;&lt;P&gt;Thank you for your help!&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2024 20:32:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/custom-arcade-data-source-returns-fewer-records/m-p/1541056#M10311</guid>
      <dc:creator>JCGuarneri</dc:creator>
      <dc:date>2024-09-20T20:32:30Z</dc:date>
    </item>
  </channel>
</rss>

