<?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: Use Arcade to Calculate Field Based on Options from Another Field in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324821#M72692</link>
    <description>&lt;P&gt;Here are two possible ways of doing it. It is a little onerous to build it for your 60 types either way, but a little easier than using if statements.&lt;/P&gt;&lt;P&gt;Using a &lt;A href="https://developers.arcgis.com/arcade/guide/types/#dictionary" target="_self"&gt;Dictionary&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var dict = {
  'Hydrant': 1,
  'Curb Stop': 2
};
var waterType = $feature.Type
return dict[waterType];&lt;/LI-CODE&gt;&lt;P&gt;Using a &lt;A href="https://developers.arcgis.com/arcade/function-reference/logical_functions/#when" target="_blank"&gt;When&lt;/A&gt; function&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var waterType = $feature.Type;
when (waterType == 'Hydrant', 1,
      waterType == 'Curb Stop', 2,
      -9999 //default value for any other type
      )&lt;/LI-CODE&gt;</description>
    <pubDate>Fri, 01 Sep 2023 16:39:53 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2023-09-01T16:39:53Z</dc:date>
    <item>
      <title>Use Arcade to Calculate Field Based on Options from Another Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324812#M72690</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I've got an Arcade question. I have a feature set of points with an attribute "Type" that details the feature type. I have another attribute that is a numeric ID that corresponds to the text attribute Type. Example: Hydrant =1, Curb Stop = 2 etc. What's the best way to write an attribute rule in Arcade that will populate the numeric ID based on the value from the text type? My knee jerk is to do a super long If/Else exchange to the effect of:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var waterType = $feature.Type
if (waterType='Hydrant'){
return 1;
}
if(waterType='Curb Stop'){
return 2;
}
etc&lt;/LI-CODE&gt;&lt;P&gt;However, there are like, 60 possible types which strikes me as a bit onerous to put into an if statement like that. Is there a better way?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 16:15:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324812#M72690</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-09-01T16:15:05Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcade to Calculate Field Based on Options from Another Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324821#M72692</link>
      <description>&lt;P&gt;Here are two possible ways of doing it. It is a little onerous to build it for your 60 types either way, but a little easier than using if statements.&lt;/P&gt;&lt;P&gt;Using a &lt;A href="https://developers.arcgis.com/arcade/guide/types/#dictionary" target="_self"&gt;Dictionary&lt;/A&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var dict = {
  'Hydrant': 1,
  'Curb Stop': 2
};
var waterType = $feature.Type
return dict[waterType];&lt;/LI-CODE&gt;&lt;P&gt;Using a &lt;A href="https://developers.arcgis.com/arcade/function-reference/logical_functions/#when" target="_blank"&gt;When&lt;/A&gt; function&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var waterType = $feature.Type;
when (waterType == 'Hydrant', 1,
      waterType == 'Curb Stop', 2,
      -9999 //default value for any other type
      )&lt;/LI-CODE&gt;</description>
      <pubDate>Fri, 01 Sep 2023 16:39:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324821#M72692</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-09-01T16:39:53Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcade to Calculate Field Based on Options from Another Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324833#M72694</link>
      <description>&lt;P&gt;Aha, yes without knowing it was thinking of a dictionary, which is a data type I'm pretty unfamiliar/uncomfortable with, so I want to try to use them more. However, I get an Arcade error that basically says the expression calculator couldn't find the attribute Type. Any thoughts on that?&lt;/P&gt;&lt;P&gt;Additionally, the second option, the When function, works perfectly!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 17:00:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324833#M72694</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-09-01T17:00:05Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcade to Calculate Field Based on Options from Another Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324846#M72696</link>
      <description>&lt;P&gt;I wasn't running into any errors on the tests I ran. What did you code look like?&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 17:33:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324846#M72696</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-09-01T17:33:58Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcade to Calculate Field Based on Options from Another Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324866#M72698</link>
      <description>&lt;P&gt;I did an abbreviated dictionary/where as a test:&lt;/P&gt;&lt;P&gt;Not working&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var dict = {
  'Gate Valve': 87,
  'Curb Stop': 12
};
var waterType = $feature.Feat_Code
return dict[waterType];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Working:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var waterType = $feature.Feat_Code;
when (waterType == 'Gate Valve', 87,
      waterType == 'Curb Stop', 12,
      -9999 //default value for any other type
      )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 18:01:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324866#M72698</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-09-01T18:01:03Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcade to Calculate Field Based on Options from Another Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324913#M72699</link>
      <description>&lt;P&gt;Does Feat_Code have a Domain? If so, you'd have to use this code&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var dict = {
  'Gate Valve': 87,
  'Curb Stop': 12
};
return dict[DomainName($feature, 'Feat_Code')];&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 19:19:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324913#M72699</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-09-01T19:19:21Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcade to Calculate Field Based on Options from Another Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324918#M72701</link>
      <description>&lt;P&gt;It does have a domain, and I had tried to use it, but I had entered it as part of the variable, like this:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var dict = {
  'Gate Valve': 87,
  'Curb Stop': 12
};
var waterType = DomainName($feature,Feat_Code)
return dict[waterType];&lt;/LI-CODE&gt;&lt;P&gt;That's clarifying, thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 19:29:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324918#M72701</guid>
      <dc:creator>ZachBodenner</dc:creator>
      <dc:date>2023-09-01T19:29:58Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcade to Calculate Field Based on Options from Another Field</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324920#M72702</link>
      <description>&lt;P&gt;Your way would have worked, but you were missing the quotes around 'Feat_Code'&lt;/P&gt;</description>
      <pubDate>Fri, 01 Sep 2023 19:42:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/use-arcade-to-calculate-field-based-on-options/m-p/1324920#M72702</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2023-09-01T19:42:43Z</dc:date>
    </item>
  </channel>
</rss>

