<?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 Arcade expression evaluating multiple field values to calculate value in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44346#M2145</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm creating a Scavenger Hunt for Collector use and want to be able to quickly grade the results in a Dashboard on ArcGIS Online. Contestants will be supplied a guide with question IDs and multiple choice answers. They will select the question ID and their multiple choice answer for each feature they record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have all of the features, fields and domains created along with some test answers. I'm trying to use the calculate value function for a hosted feature service in ArcGIS Online to add a "Y" or "N" value to a new 'Corrected' field to indicate if they got they answer right or wrong. (This field will be hidden from them in the Collector web map)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My logic is that I want any collected feature (row) whose QuestionID == "1" AND MultChoice == "A" to get a "Y" assigned to the new 'Corrected' field. I will list all of the correct combinations of Question IDs and Multiple Choice answers in this manner. Else, all other values will be assigned "N".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've been experimenting with the Arcade Expression builder box in ArcGIS Online, but it seems to be lacking in its syntax troubleshooting capabilities and I'm not getting anywhere. It doesn't seem I can evaluate a compound expression. I'm thinking I need to create a variable based on a filter (the easiest way would be all questions with Multiple Choice == "A" become variable 'MultiA', "B" becomes 'MultiB", etc.), and then evaluate an IIF statement for each of those variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any Arcade wizards out there care to enlighten me?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 09 Apr 2019 01:56:30 GMT</pubDate>
    <dc:creator>JoeBryant1</dc:creator>
    <dc:date>2019-04-09T01:56:30Z</dc:date>
    <item>
      <title>Arcade expression evaluating multiple field values to calculate value</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44346#M2145</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm creating a Scavenger Hunt for Collector use and want to be able to quickly grade the results in a Dashboard on ArcGIS Online. Contestants will be supplied a guide with question IDs and multiple choice answers. They will select the question ID and their multiple choice answer for each feature they record.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have all of the features, fields and domains created along with some test answers. I'm trying to use the calculate value function for a hosted feature service in ArcGIS Online to add a "Y" or "N" value to a new 'Corrected' field to indicate if they got they answer right or wrong. (This field will be hidden from them in the Collector web map)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My logic is that I want any collected feature (row) whose QuestionID == "1" AND MultChoice == "A" to get a "Y" assigned to the new 'Corrected' field. I will list all of the correct combinations of Question IDs and Multiple Choice answers in this manner. Else, all other values will be assigned "N".&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've been experimenting with the Arcade Expression builder box in ArcGIS Online, but it seems to be lacking in its syntax troubleshooting capabilities and I'm not getting anywhere. It doesn't seem I can evaluate a compound expression. I'm thinking I need to create a variable based on a filter (the easiest way would be all questions with Multiple Choice == "A" become variable 'MultiA', "B" becomes 'MultiB", etc.), and then evaluate an IIF statement for each of those variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any Arcade wizards out there care to enlighten me?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2019 01:56:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44346#M2145</guid>
      <dc:creator>JoeBryant1</dc:creator>
      <dc:date>2019-04-09T01:56:30Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression evaluating multiple field values to calculate value</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44347#M2146</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;What you can do is this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="comment token"&gt;// create a disctionary with the correct answer for each question ID&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; answers &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"1"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"A"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"2"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"C"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; 
               &lt;SPAN class="string token"&gt;"3"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"B"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"4"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"A"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;
               &lt;SPAN class="string token"&gt;"5"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"D"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"6"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"D"&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;// read the fields that contain the question ID and user answer&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; QuestionID &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; $feature&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;QuestionID1&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; UserAnswer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; $feature&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Answer1&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;

&lt;SPAN class="comment token"&gt;// validate the answer&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;HasKey&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;answers&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; QuestionID&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;var&lt;/SPAN&gt; CorrectAnswer &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; answers&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;QuestionID&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;UserAnswer &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; CorrectAnswer&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Y"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
    &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
        &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"N"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
    &lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;else&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;{&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;return&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"?"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="punctuation token"&gt;}&lt;/SPAN&gt;
&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;On the first rows you can create a dictionary that holds all the question IDs together with the correct answer (lines 2 - 5).&lt;/LI&gt;&lt;LI&gt;Line 7 and 8 will read the fields that hold the ID and answer of the user&lt;/LI&gt;&lt;LI&gt;lines 12 to 21 will validate if the ID is in the dictionary and if so, extract the correct answer for the ID and validate is it matches the answer provided by the user and assign a Y or N (or ?).&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could also extract multiple answers and calculate the score in %.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:42:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44347#M2146</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-10T21:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression evaluating multiple field values to calculate value</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44348#M2147</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xander, you're awesome! This is exactly what I needed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I hadn't thought of creating a dictionary for the correct answers. Very clean.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have not used the "HasKey" function before. This seems to be the essential piece of this script. When I read it and try to understand the logic, my head still turns in circles. I think it's going to take me a while to master that one.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Hopefully others find this post and can benefit. Thanks again; you saved my bacon!&amp;nbsp;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2019 17:59:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44348#M2147</guid>
      <dc:creator>JoeBryant1</dc:creator>
      <dc:date>2019-04-09T17:59:33Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression evaluating multiple field values to calculate value</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44349#M2148</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&amp;nbsp;&lt;A href="https://community.esri.com/migrated-users/352743"&gt;Joe Bryant&lt;/A&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm glad&amp;nbsp;it worked for you.&amp;nbsp;As you probably noticed the dictionary consists of key: value pairs. So "1" is the key (the QuestionID) and "A" is the value (the correct answer for question with ID "1"). When using the HasKey function you are checking is the key (question ID) exists in the dictionary. If it doesn't we skip directly to the part where "?" is returned. If the key (question ID) exists in the dictionary we extract the correct answer. This is done by&amp;nbsp;DictionaryName[QuestionID]. The reason is used is to avoid that an error&amp;nbsp;is triggered when we try to use a key that does not exist in the dictionary. I hope this makes it a bit easier to understand.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2019 18:42:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44349#M2148</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2019-04-09T18:42:22Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade expression evaluating multiple field values to calculate value</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44350#M2149</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes, that does clarify it. I had not grasped that the dictionary is more than a list; it is a list of key:value pairs. And you can return the value by using the key with the expression “DictionaryName[key]”.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Joe Bryant&lt;/P&gt;&lt;P&gt;GIS Coordinator&lt;/P&gt;&lt;P&gt;WEST YOST ASSOCIATES&lt;/P&gt;&lt;P&gt;direct 530.761.0226&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 09 Apr 2019 19:15:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/arcade-expression-evaluating-multiple-field-values/m-p/44350#M2149</guid>
      <dc:creator>JoeBryant1</dc:creator>
      <dc:date>2019-04-09T19:15:19Z</dc:date>
    </item>
  </channel>
</rss>

