<?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 Field Calculation Error in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/arcade-field-calculation-error/m-p/1278286#M6551</link>
    <description>&lt;P&gt;Your code was taking so long since you were cycling through all 28K features in table 2 for each feature in table 1. And it wasn't finding the correct output, since you were comparing the first record in Table 2 to your feature, instead of the looped feature in table 2 ("feat.FACILITYID" instead of "f.FACILITYID").&lt;/P&gt;&lt;P&gt;Give this a try. It filters table 2 by the FACILITYID of the feature in table 1. If there is a corresponding record in table 2, then it return 1. Otherwise, it returns null (which isn't explicitly needed in this script in my testing)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var commericalLine = FeatureSetByName($datastore,"CommericalLine_Table")
var id = $feature.FACILITYID
var filteredTable = Filter(commericalLine, "FACILITYID = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/354972"&gt;@ID&lt;/a&gt;")
if (Count(filteredTable) &amp;gt; 0) return 1;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 13 Apr 2023 14:53:30 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2023-04-13T14:53:30Z</dc:date>
    <item>
      <title>Arcade Field Calculation Error</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-field-calculation-error/m-p/1277963#M6547</link>
      <description>&lt;P&gt;I'm struggling to complete a field calculation using Arcade. I'm trying to calculate a field in table 1 based on a field from table 2. Both tables exist in the same file geodatabase.&amp;nbsp;&lt;/P&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var commericalLine = FeatureSetByName($datastore,'CommericalLine_Table')

if ($feature["FACILITYID"] == commericalLine["FACILITYID"]) {
    return 1
}

else{
   return Null 
}&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;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I go to validate the expression, I receive the following error message:&lt;/P&gt;&lt;P&gt;Invalid Expression.&lt;/P&gt;&lt;P&gt;Error on line 3&lt;/P&gt;&lt;P&gt;Dictionary type expected.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions on how to resolve this?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 19:26:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-field-calculation-error/m-p/1277963#M6547</guid>
      <dc:creator>DylanW_TOC</dc:creator>
      <dc:date>2023-04-12T19:26:55Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Field Calculation Error</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-field-calculation-error/m-p/1277977#M6548</link>
      <description>&lt;P&gt;FeatureSetByName returns a FeatureSet, not a single feature. You have to get a feature from that FeatureSet to do the comparison. If you're expecting there to be one feature, then you can use &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#first" target="_self"&gt;First&lt;/A&gt; to return that feature. If there are multiple features in that FeatureSet, you'll have to &lt;A href="https://developers.arcgis.com/arcade/guide/loops/#featureset" target="_self"&gt;loop&lt;/A&gt; through them or use a &lt;A href="https://developers.arcgis.com/arcade/function-reference/featureset_functions/#filter" target="_self"&gt;Filter&lt;/A&gt; to get a specific one. If you use a Filter, remember that function will also return a FeatureSet and you'll need to use First to get the single feature.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var commericalLine = FeatureSetByName($datastore,'CommericalLine_Table')
var feat = First(commercialLine);
if ($feature["FACILITYID"] == feat["FACILITYID"]) {
    return 1
}
else{
   return Null 
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 19:51:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-field-calculation-error/m-p/1277977#M6548</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-04-12T19:51:44Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Field Calculation Error</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-field-calculation-error/m-p/1278196#M6550</link>
      <description>&lt;P&gt;Thanks for the response, Ken. I tried out the code below, but it only matched one record (out of 28k) when it should have matched 3k&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var commericalLine = FeatureSetByName($datastore,"CommericalLine_Table")
var feat = First(commericalLine)

for (var f in commericalLine){
    if ($feature.FACILITYID == feat.FACILITYID){
        return 1
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another thing, it took over 10 minutes to complete this calculation does that sound right?&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 12:19:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-field-calculation-error/m-p/1278196#M6550</guid>
      <dc:creator>DylanW_TOC</dc:creator>
      <dc:date>2023-04-13T12:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Field Calculation Error</title>
      <link>https://community.esri.com/t5/developers-questions/arcade-field-calculation-error/m-p/1278286#M6551</link>
      <description>&lt;P&gt;Your code was taking so long since you were cycling through all 28K features in table 2 for each feature in table 1. And it wasn't finding the correct output, since you were comparing the first record in Table 2 to your feature, instead of the looped feature in table 2 ("feat.FACILITYID" instead of "f.FACILITYID").&lt;/P&gt;&lt;P&gt;Give this a try. It filters table 2 by the FACILITYID of the feature in table 1. If there is a corresponding record in table 2, then it return 1. Otherwise, it returns null (which isn't explicitly needed in this script in my testing)&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var commericalLine = FeatureSetByName($datastore,"CommericalLine_Table")
var id = $feature.FACILITYID
var filteredTable = Filter(commericalLine, "FACILITYID = &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/354972"&gt;@ID&lt;/a&gt;")
if (Count(filteredTable) &amp;gt; 0) return 1;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 13 Apr 2023 14:53:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/arcade-field-calculation-error/m-p/1278286#M6551</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-04-13T14:53:30Z</dc:date>
    </item>
  </channel>
</rss>

