<?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: Help with Arcade Expression in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120146#M48283</link>
    <description>&lt;P&gt;One step closer, now I am getting a general evaluation error for line 6. Is this a syntax issue?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var filt_val = $feature.Field1
var fs = FeatureSetByName($datastore, 'combined_points')

var list = Filter(fs, 'Field1 = @filt_val')
var OriginalDate = Min(list, 'Field6')
var OriginalNorthing = First(Filter(list, 'Field6 = @OriginalDate'))

return $feature.Field2 - OriginalNorthing.Field2&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TimothyMcKinney_0-1637791128612.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/28228iC229782A90176F03/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TimothyMcKinney_0-1637791128612.png" alt="TimothyMcKinney_0-1637791128612.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 24 Nov 2021 21:59:42 GMT</pubDate>
    <dc:creator>TimothyMcKinney</dc:creator>
    <dc:date>2021-11-24T21:59:42Z</dc:date>
    <item>
      <title>Help with Arcade Expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120065#M48276</link>
      <description>&lt;P&gt;I am trying to create an arcade expression for a calculated field in my table. Any help with the proper syntax would be helpful. My table contains multiple entries with repeating values in field1 and different dates in field6. I want to find the the first entry (based on date) and perform a calculation with a field from that entry. This needs to be done per unique item in field 1.&lt;/P&gt;&lt;P&gt;Please see attached image for an idea of what I am trying to do. If I understand it correctly I believe I just need one more function to get the specific field value I need.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sql"&gt;var list = Filter($featureset, 'Field1 = $feature.Field1')
var OriginalDate = Min(list, "Field6")
var OriginalNorthing = Filter(list, 'Field6 = OriginalDate')
return $feature.Field2 - OriginalNorthing&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 20:56:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120065#M48276</guid>
      <dc:creator>TimothyMcKinney</dc:creator>
      <dc:date>2021-11-24T20:56:31Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Arcade Expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120096#M48278</link>
      <description>&lt;P&gt;First things first: click&lt;STRONG&gt; Expand Toolbar → Insert/Edit Code Sample&lt;/STRONG&gt; for these sorts of things. It is &lt;EM&gt;much &lt;/EM&gt;easier to troubleshoot someone's code when it can be copied and pasted.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1637786154124.png" style="width: 200px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/28209i362E7EFC99DB6494/image-size/small?v=v2&amp;amp;px=200" role="button" title="jcarlson_0-1637786154124.png" alt="jcarlson_0-1637786154124.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="jcarlson_1-1637786170795.png" style="width: 200px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/28210iDA22B8742183CC83/image-size/small?v=v2&amp;amp;px=200" role="button" title="jcarlson_1-1637786170795.png" alt="jcarlson_1-1637786170795.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;On to the code itself. You're right, you're about one step away from figuring it out, though it's not a function.&lt;/P&gt;&lt;P&gt;When you &lt;STRONG&gt;filter &lt;/STRONG&gt;a &lt;EM&gt;FeatureSet&lt;/EM&gt;, the function returns &lt;EM&gt;another &lt;/EM&gt;FeatureSet. To access the attributes of an individual feature, you have to pull the feature out somehow. In your case, it's very simple, since the &lt;EM&gt;OriginalNorthing&lt;/EM&gt; FeatureSet only has a single item in it. We'll use &lt;STRONG&gt;First&lt;/STRONG&gt; to grab the first item in the set, then use the usual notation to get a specific attribute.&lt;/P&gt;&lt;P&gt;Also, keep in mind that the expression in a &lt;STRONG&gt;Filter &lt;/STRONG&gt;function has to be SQL-92 compatible, so the field notation from Arcade won't work. To bring an outside variable in, simply declare it elsewhere in your expression and reference it with an "@".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var filt_val = $feature.Field1

var list = Filter($layer, 'Field1 = @filt_val')

var OriginalDate = Min(list, 'Field6')

var OriginalNorthing = First(Filter(list, 'Field6 = @OriginalDate'))

return $feature.Field2 - OriginalNorthing.Field2&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 20:48:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120096#M48278</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-11-24T20:48:41Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Arcade Expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120114#M48279</link>
      <description>&lt;P&gt;Thank you for the help. When adding arcade code snippets in since there is no arcade language listed is there a "best" one to select from the drop down for formatting purposes? For now I added it to my original post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Second, I tried your code and get an object error:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TimothyMcKinney_0-1637787828217.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/28215i098E0A8464120A37/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TimothyMcKinney_0-1637787828217.png" alt="TimothyMcKinney_0-1637787828217.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Earlier I tried using $layer and was getting an object error so I changed it to $featureset as shown in my code above. If I do this in your code it ends up causing another error in in line 7. Any thoughts on what could be causing the object error?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for your help so far.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 21:10:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120114#M48279</guid>
      <dc:creator>TimothyMcKinney</dc:creator>
      <dc:date>2021-11-24T21:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Arcade Expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120121#M48280</link>
      <description>&lt;P&gt;Using javascript is usually good enough for syntax highlighting.&lt;/P&gt;&lt;P&gt;Why don't we try using a &lt;STRONG&gt;FeatureSetBy &lt;/STRONG&gt;function, as they're a little more specific.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var filt_val = $feature.Field1
var fs = FeatureSetByName($datastore, 'your-layer-name-goes-here')

var list = Filter(fs, 'Field1 = @filt_val')
var OriginalDate = Min(list, 'Field6')
var OriginalNorthing = First(Filter(list, 'Field6 = @OriginalDate'))

return $feature.Field2 - OriginalNorthing.Field2&lt;/LI-CODE&gt;&lt;P&gt;Note: the name you put into the function should match the table name as it's&amp;nbsp;&lt;STRONG&gt;stored&lt;/STRONG&gt; in the data store / file, not any alias that you've applied to it.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 21:17:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120121#M48280</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-11-24T21:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Arcade Expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120146#M48283</link>
      <description>&lt;P&gt;One step closer, now I am getting a general evaluation error for line 6. Is this a syntax issue?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var filt_val = $feature.Field1
var fs = FeatureSetByName($datastore, 'combined_points')

var list = Filter(fs, 'Field1 = @filt_val')
var OriginalDate = Min(list, 'Field6')
var OriginalNorthing = First(Filter(list, 'Field6 = @OriginalDate'))

return $feature.Field2 - OriginalNorthing.Field2&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TimothyMcKinney_0-1637791128612.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/28228iC229782A90176F03/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TimothyMcKinney_0-1637791128612.png" alt="TimothyMcKinney_0-1637791128612.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 21:59:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120146#M48283</guid>
      <dc:creator>TimothyMcKinney</dc:creator>
      <dc:date>2021-11-24T21:59:42Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Arcade Expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120158#M48284</link>
      <description>&lt;P&gt;Strange. I think it would tell us if it was syntax related. Any chance this layer is accessible in a web map?&lt;/P&gt;&lt;P&gt;If you can utilize the AGOL / Portal expression builder, you can use the Console command to output intermediate things, like the contents of your &lt;STRONG&gt;list &lt;/STRONG&gt;and &lt;STRONG&gt;OriginalDate&lt;/STRONG&gt; objects, to make sure that the preceding steps are going as intended.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1637791913004.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/28232i7582F3A36F20C8A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1637791913004.png" alt="jcarlson_0-1637791913004.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Barring that, you'll just have to figure out some other way of testing the individual components of this expression. Try putting the &lt;STRONG&gt;First&lt;/STRONG&gt; function on its own line, perhaps, to see if that's the cause.&lt;/P&gt;&lt;P&gt;Or maybe it's related to how you're assembling the query? &lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/mapping/navigation/sql-reference-for-elements-used-in-query-expressions.htm#GUID-85C03D85-F4A5-48FC-8E8C-3F79919430DB" target="_blank"&gt;According to the docs&lt;/A&gt;, there are database-specific ways to indicate that you're supplying a datetime value.&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 22:17:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120158#M48284</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-11-24T22:17:05Z</dc:date>
    </item>
    <item>
      <title>Re: Help with Arcade Expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120185#M48289</link>
      <description>&lt;P&gt;It was definitely an issues with the dates. After switching fields with the min function it worked so I assume the min function does not work with dates? Either way I tried a different solution to find the earliest date and OrderBy fit the bill.&lt;/P&gt;&lt;P&gt;First attempt:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var filt_val = $feature.Field1
var fs = FeatureSetByName($datastore, 'combined_points')

var list = Filter(fs, 'Field1 = @filt_val')
var OriginalEntry = First(Top(OrderBy(list, 'Field6 ASC'), 2))

var OriginalNorthing = First(Filter(list, 'Field6 = OriginalEntry.Field6'))
return $feature.Field2 - OriginalNorthing.Field2&lt;/LI-CODE&gt;&lt;P&gt;This was valid however it wasn't the solution I expected as I was not getting the value from the earliest date. So either a problem with line 5 (my sorting) or 7 (the filter using the earliest date). I found out it wasn't my sorting, see below. Not sure what is causing the filtering from line 7 to not work as expected, maybe another day I will figure that one out.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After some trial and error this is working so far, will test some to make sure:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var filt_val = $feature.Field1
var fs = FeatureSetByName($datastore, 'combined_points')

var list = Filter(fs, 'Field1 = @filt_val')
var OriginalEntry = First(Top(OrderBy(list, 'Field6 ASC'), 2))
var OriginalNorthing = OriginalEntry.Field2

return $feature.Field2 - OriginalNorthing&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again for all of the help. I will have to do some more research on the AGOL / Portal expression builder for the future. I am used to fumbling through python notebooks in Pro and being able to print intermediate results is a must!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 24 Nov 2021 23:33:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/help-with-arcade-expression/m-p/1120185#M48289</guid>
      <dc:creator>TimothyMcKinney</dc:creator>
      <dc:date>2021-11-24T23:33:11Z</dc:date>
    </item>
  </channel>
</rss>

