<?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 Data Expression - Latest Sample Date and Second Latest Sample Date in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-latest-sample-date-and/m-p/1227397#M6957</link>
    <description>&lt;P&gt;Instead of getting the first row of the filtered featureset, you need a second for loop:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Populate feature array
for (var site in sites) {
    var id = site.siteID
    // get all samples for this site, ordered by date
    var samples = OrderBy(Filter(fs, 'siteID = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/354972"&gt;@ID&lt;/a&gt;'), 'sampleDate DESC')
    var i = 0
    var prevDate
    // loop through the samples
    for(var sample in samples) {
        // abort after second feature
        i += 1
        if(i &amp;gt; 2) { break }
        // abort if second feature has different date
        if(i == 2 &amp;amp;&amp;amp; Text(sample.sampleDate, 'Y-MM-DD') != Text(prevDate, 'Y-MM-DD')) { break }
        // store date
        prevDate = sample.sampleDate
        // create the new feature and push it into the output fs
        var feat = {
            'attributes': {
                //...
        }}
        Push(dowDict.features, feat);
    }
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 01 Nov 2022 11:36:46 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2022-11-01T11:36:46Z</dc:date>
    <item>
      <title>Arcade Data Expression - Latest Sample Date and Second Latest Sample Date</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-latest-sample-date-and/m-p/1227159#M6955</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;am trying to create a cleaned up table that shows the most recent available&amp;nbsp;date for each ['siteID'] while still showing the associated COVID variant values [sys_estFreqReads_DeltaB16172,....).&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;In some cases some SiteIDs will have two samples for the same Date and I would like both samples to be shown in the final product output. I was trying to see if another If statement that would see if the date in the latest sample date but it seems like Arcade doesn't let me do that. Is there another way of doing it ?&lt;/P&gt;&lt;P&gt;Something like that:&lt;/P&gt;&lt;P&gt;// samples&lt;BR /&gt;var sample_list = OrderBy(samples, 'sampleDate DESC')&lt;/P&gt;&lt;P&gt;if(latest_sample.sampleDate == sample_list[1].sampleDate )&lt;BR /&gt;latest_sample = sample_list[1]&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HashemAbdo_1-1667239524988.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/54850i0CF5B5438065EF07/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HashemAbdo_1-1667239524988.png" alt="HashemAbdo_1-1667239524988.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Updated code:&lt;/P&gt;&lt;P&gt;var portal = Portal('&lt;A href="https://arcgis.com/" target="_blank" rel="noopener nofollow noreferrer"&gt;https://arcgis.com&lt;/A&gt;');&lt;/P&gt;&lt;P&gt;var fs = FeatureSetByPortalItem(&lt;BR /&gt;portal,&lt;BR /&gt;'XXXX',&lt;BR /&gt;0,&lt;BR /&gt;[&lt;BR /&gt;'sys_estFreqReads_DeltaB16172',&lt;BR /&gt;'sys_estFreqReads_OmicronBA1',&lt;BR /&gt;'sys_estFreqReads_OmicronBA2',&lt;BR /&gt;'sys_estFreqReads_OmicronBA4',&lt;BR /&gt;'sys_estFreqReads_OmicronBA5',&lt;BR /&gt;'sys_estFreqReads_OmicronBA275',&lt;BR /&gt;'sys_sewershedName',&lt;BR /&gt;'sys_phu',&lt;BR /&gt;'sampleDate',&lt;BR /&gt;'siteID',&lt;BR /&gt;'lowQuality'&lt;BR /&gt;],&lt;BR /&gt;false&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;var dowDict = {&lt;BR /&gt;'fields': [&lt;BR /&gt;{ 'name': 'sampleDate', 'type': 'esriFieldTypeString'},&lt;BR /&gt;{ 'name': 'siteID', 'type': 'esriFieldTypeString'},&lt;BR /&gt;{'name': 'sys_phu', 'type': 'esriFieldTypeString'},&lt;BR /&gt;{'name': 'sys_sewershedName', 'type': 'esriFieldTypeString'},&lt;BR /&gt;{ 'name': 'sys_estFreqReads_DeltaB16172', 'type': 'esriFieldTypeDouble'},&lt;BR /&gt;{ 'name': 'sys_estFreqReads_OmicronBA1', 'type': 'esriFieldTypeDouble'},&lt;BR /&gt;{ 'name': 'sys_estFreqReads_OmicronBA2', 'type': 'esriFieldTypeDouble'},&lt;BR /&gt;{ 'name': 'sys_estFreqReads_OmicronBA4', 'type': 'esriFieldTypeDouble'},&lt;BR /&gt;{ 'name': 'sys_estFreqReads_OmicronBA5', 'type': 'esriFieldTypeDouble'},&lt;BR /&gt;{ 'name': 'sys_estFreqReads_OmicronBA275', 'type': 'esriFieldTypeDouble'},&lt;BR /&gt;{ 'name': 'dow_num', 'type': 'esriFieldTypeInteger'},&lt;BR /&gt;{'name': 'dow', 'type': 'esriFieldTypeString'},&lt;BR /&gt;{'name': 'lowQuality', 'type': 'esriFieldTypeString'}&lt;BR /&gt;&lt;BR /&gt;],&lt;BR /&gt;'geometryType': '',&lt;BR /&gt;'features': []&lt;BR /&gt;};&lt;BR /&gt;// get all distinct combinations of ['siteID','sys_phu', 'sys_sewershedName']&lt;BR /&gt;//var sites = Distinct(fs, ['siteID','sys_phu', 'sys_sewershedName'])&lt;BR /&gt;var sites = Distinct(fs, ['siteID'])&lt;/P&gt;&lt;P&gt;// Create array for holding features, feat object for populating array&lt;BR /&gt;var features = [];&lt;BR /&gt;var feat;&lt;/P&gt;&lt;P&gt;//var newdate2 = Text($datapoint["sampleDate"],'DD-MMM-YY');&lt;/P&gt;&lt;P&gt;// Populate feature array&lt;BR /&gt;for (var site in sites) {&lt;BR /&gt;var id = site.siteID&lt;BR /&gt;//var phu = site.sys_phu&lt;BR /&gt;//var sewershed = site.sys_sewershedName&lt;BR /&gt;// get all samples for this site&lt;BR /&gt;var samples = Filter(fs,'siteID =&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.esri.com/t5/user/viewprofilepage/user-id/354972" target="_blank"&gt;@ID&lt;/A&gt;')&lt;BR /&gt;// get the latest sample&lt;BR /&gt;var latest_sample = First(OrderBy(samples, 'sampleDate DESC'))&lt;/P&gt;&lt;P&gt;// samples&lt;BR /&gt;var sample_list = OrderBy(samples, 'sampleDate DESC')&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;// null check to avoid errors&lt;BR /&gt;if(latest_sample == null) { continue }&lt;BR /&gt;// create the new feature and push it into the output fs&lt;BR /&gt;feat = {&lt;BR /&gt;'attributes': {&lt;BR /&gt;'sampleDate': Text(latest_sample['sampleDate'],'D-MMM-YY'),&lt;BR /&gt;'siteID': (latest_sample['siteID']),&lt;BR /&gt;'sys_phu': Text(latest_sample['sys_phu']),&lt;BR /&gt;'sys_sewershedName': Text(latest_sample['sys_sewershedName']),&lt;BR /&gt;'sys_estFreqReads_DeltaB16172': (latest_sample['sys_estFreqReads_DeltaB16172']),&lt;BR /&gt;'sys_estFreqReads_OmicronBA1': (latest_sample['sys_estFreqReads_OmicronBA1']),&lt;BR /&gt;'sys_estFreqReads_OmicronBA2': (latest_sample['sys_estFreqReads_OmicronBA2']),&lt;BR /&gt;'sys_estFreqReads_OmicronBA4': (latest_sample['sys_estFreqReads_OmicronBA4']),&lt;BR /&gt;'sys_estFreqReads_OmicronBA5': (latest_sample['sys_estFreqReads_OmicronBA5']),&lt;BR /&gt;'sys_estFreqReads_OmicronBA275': (latest_sample['sys_estFreqReads_OmicronBA275']),&lt;BR /&gt;'dow_num': Weekday(latest_sample['sampleDate']),&lt;BR /&gt;'dow': Text(latest_sample['sampleDate'], 'dddd'),&lt;BR /&gt;'lowQuality': Text(latest_sample['lowQuality']),&lt;BR /&gt;&lt;BR /&gt;}}&lt;BR /&gt;Push(dowDict.features, feat);&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;// Convert dictionary to feature set.&lt;BR /&gt;//var fs_dict = FeatureSet(Text(dowDict));&lt;BR /&gt;return FeatureSet(Text(dowDict));&lt;/P&gt;&lt;P&gt;&amp;nbsp; @&lt;SPAN class=""&gt;&lt;A href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341" target="_self"&gt;JohannesLindner&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;,&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 18:08:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-latest-sample-date-and/m-p/1227159#M6955</guid>
      <dc:creator>HashemAbdo</dc:creator>
      <dc:date>2022-10-31T18:08:42Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression - Latest Sample Date and Second Latest Sample Date</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-latest-sample-date-and/m-p/1227397#M6957</link>
      <description>&lt;P&gt;Instead of getting the first row of the filtered featureset, you need a second for loop:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Populate feature array
for (var site in sites) {
    var id = site.siteID
    // get all samples for this site, ordered by date
    var samples = OrderBy(Filter(fs, 'siteID = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/354972"&gt;@ID&lt;/a&gt;'), 'sampleDate DESC')
    var i = 0
    var prevDate
    // loop through the samples
    for(var sample in samples) {
        // abort after second feature
        i += 1
        if(i &amp;gt; 2) { break }
        // abort if second feature has different date
        if(i == 2 &amp;amp;&amp;amp; Text(sample.sampleDate, 'Y-MM-DD') != Text(prevDate, 'Y-MM-DD')) { break }
        // store date
        prevDate = sample.sampleDate
        // create the new feature and push it into the output fs
        var feat = {
            'attributes': {
                //...
        }}
        Push(dowDict.features, feat);
    }
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 11:36:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-latest-sample-date-and/m-p/1227397#M6957</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-11-01T11:36:46Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Data Expression - Latest Sample Date and Second Latest Sample Date</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-latest-sample-date-and/m-p/1227620#M6958</link>
      <description>&lt;P&gt;This worked !!!! Thank you so much&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 19:27:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-data-expression-latest-sample-date-and/m-p/1227620#M6958</guid>
      <dc:creator>HashemAbdo</dc:creator>
      <dc:date>2022-11-01T19:27:47Z</dc:date>
    </item>
  </channel>
</rss>

