<?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 Advanced Formatting - Feature to Feature Time Delta in ArcGIS Online Developers Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-developers-questions/arcade-advanced-formatting-feature-to-feature-time/m-p/1137359#M1085</link>
    <description>&lt;P&gt;Thanks for the help. I haven't gotten it to work for my use-case yet but I'm working on it. If it does end up working, i'll nominate you as DS emeritus.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jan 2022 13:43:15 GMT</pubDate>
    <dc:creator>DougZietz1</dc:creator>
    <dc:date>2022-01-26T13:43:15Z</dc:date>
    <item>
      <title>Arcade Advanced Formatting - Feature to Feature Time Delta</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/arcade-advanced-formatting-feature-to-feature-time/m-p/1134581#M1074</link>
      <description>&lt;P&gt;Is there a way to replicate dataframe.shift() from pandas in Ops Dashboard List or Table Widget using Advanced Formatting? I need to calc the time delta from feature to feature. I know I can pre-calculate for the entire dataset and add to my hosted table or calculate from the feature set via Data Expressions but that will be for the entire dataset. I want to be able to use the selector widgets to filter features then calculate the time delta dynamically.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 15:21:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/arcade-advanced-formatting-feature-to-feature-time/m-p/1134581#M1074</guid>
      <dc:creator>DougZietz1</dc:creator>
      <dc:date>2022-01-18T15:21:44Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Advanced Formatting - Feature to Feature Time Delta</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/arcade-advanced-formatting-feature-to-feature-time/m-p/1134628#M1075</link>
      <description>&lt;P&gt;Ordinarily, the &lt;A href="https://developers.arcgis.com/arcade/function-reference/date_functions/#datediff" target="_blank"&gt;DateDiff function&lt;/A&gt; is what you want. The trouble, though, is that the Advanced Formatting profile doesn't give you access to the other features in the layer. If you have the indicator set to "Feature", you can at least get at your single feature's attributes, but there's no way to reference another layer.&lt;/P&gt;&lt;P&gt;Well, there's the reference layer, but that only works with numeric statistics, not date fields. But then, date fields are just integers in different clothes, so maybe there's something we can do here.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-SPOILER&gt;It works, but it's&amp;nbsp;&lt;EM&gt;super&lt;/EM&gt; hacky.&lt;/LI-SPOILER&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H4&gt;Data Expression Layer&lt;/H4&gt;&lt;P&gt;To get this to work, we do need to use a data expression, but just to convert our date to a number.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal('https://arcgis.com')

var fs = FeatureSetByPortalItem(
    portal,
    '0c5c1be4122b42fca2aa8706ecfa4356',
    0,
    ['some_date', 'type'],
    false
)

var features = []
var feat

for(var f in fs){
    feat = {
        attributes: {
            date_num: Number(f['some_date']),
            type: f['type']
        }
    }
    
    Push(features, feat)
}

var fs_dict = {
    fields: [
        {name: 'date_num', type: 'esriFieldTypeSingle'},
        {name: 'type', type: 'esriFieldTypeInteger'}],
    geometryType: '',
    features: features
}

return FeatureSet(Text(fs_dict))&lt;/LI-CODE&gt;&lt;H4&gt;Indicator Settings&lt;/H4&gt;&lt;P&gt;I've got my indicator looking at the data expression, and it's set to &lt;STRONG&gt;Feature&lt;/STRONG&gt;. I also have a reference value set, and that's looking at the &lt;EM&gt;Maximum&lt;/EM&gt; date number of the same expression. I'm also limiting it to a single feature.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_2-1642523120903.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31709i4992C3669D1E8E56/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_2-1642523120903.png" alt="jcarlson_2-1642523120903.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;H4&gt;Advanced Formatting&lt;/H4&gt;&lt;P&gt;Now we've got two numbers that we've forced into the indicator's requirements, and a bit of Arcade can bring them back as dates.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var feat_date = Date($datapoint["date_num"])
var ref_date = Date($reference["max_date_num"])
var duration = Abs(DateDiff(feat_date, ref_date, 'days'))

return {
    topText: `Feature Date: ${Text(feat_date, 'DD MMM YYYY')}`,
    middleText: `Reference Date: ${Text(ref_date, 'DD MMM YYYY')}`,
    bottomText: `Date Diff: ${Round(duration)} days`
  }&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_1-1642523072653.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31708i25774055187DD05B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_1-1642523072653.png" alt="jcarlson_1-1642523072653.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;H4&gt;Selectors and Filtering&lt;/H4&gt;&lt;P&gt;I've got two selectors set up. One targets the indicator value, one targets the reference. Both are based on the features in the expression.&lt;/P&gt;&lt;P&gt;If you wanted this to look nicer, you could amend the data expression to include additional fields for labeling, etc. &lt;/P&gt;&lt;P&gt;And that should do it!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="firefox_73XuzytGY3.gif" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/31711i12A572548BE48BE7/image-size/medium?v=v2&amp;amp;px=400" role="button" title="firefox_73XuzytGY3.gif" alt="firefox_73XuzytGY3.gif" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 18 Jan 2022 16:43:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/arcade-advanced-formatting-feature-to-feature-time/m-p/1134628#M1075</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-01-18T16:43:38Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Advanced Formatting - Feature to Feature Time Delta</title>
      <link>https://community.esri.com/t5/arcgis-online-developers-questions/arcade-advanced-formatting-feature-to-feature-time/m-p/1137359#M1085</link>
      <description>&lt;P&gt;Thanks for the help. I haven't gotten it to work for my use-case yet but I'm working on it. If it does end up working, i'll nominate you as DS emeritus.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jan 2022 13:43:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-developers-questions/arcade-advanced-formatting-feature-to-feature-time/m-p/1137359#M1085</guid>
      <dc:creator>DougZietz1</dc:creator>
      <dc:date>2022-01-26T13:43:15Z</dc:date>
    </item>
  </channel>
</rss>

