<?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: Calculate field based on previous dropdown question in survey in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/calculate-field-based-on-previous-dropdown/m-p/1192336#M43739</link>
    <description>&lt;P&gt;In Survey123, the&amp;nbsp;&lt;STRONG&gt;if&lt;/STRONG&gt; function follows the syntax&lt;/P&gt;&lt;PRE&gt;if(condition, return if true, return if false)&lt;/PRE&gt;&lt;P&gt;So, for the example expression you give, you'd need to write this out as follows (I'll use line breaks to make this clearer):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if(
    ${hospital} == 'Facility1' or ${hospital} == 'Facility2',
    'Region 1',
    if(
        $[hospital} == 'Facility3' or ${hospital} == 'Facility4' or ${hospital} == 'Facility5',
        Region 2',
        ''
    )
)
&lt;/LI-CODE&gt;&lt;P&gt;You'll need that all in one line for it to work properly, but note how multiple conditions have to be specified clearly. It feels linguistically sensible to say "${hospital} = 'A' or 'B', but programmatically, your survey is going to treat 'B' as its own condition.&lt;/P&gt;&lt;P&gt;For a large number of potential hospitals and regions, this can make for a&amp;nbsp;&lt;EM&gt;large&lt;/EM&gt; expression, but at least you'll only need to write it once.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Jul 2022 20:49:57 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2022-07-14T20:49:57Z</dc:date>
    <item>
      <title>Calculate field based on previous dropdown question in survey</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/calculate-field-based-on-previous-dropdown/m-p/1192320#M43738</link>
      <description>&lt;P&gt;Hello! I'm trying to populate data based on dropdown answer higher up in the survey. Essentially a hospital has to select their name, then I'd like a hidden field that assigns the region they are in. I have 84 hospitals in 6 regions. I tried:&lt;/P&gt;&lt;P&gt;if(${hospital}, 'Facility1' or 'Facility2'), 'Region 1', if($[hospital}, 'Facility3' or 'Facility4' or 'Facility5', Region 2', '')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't know it the syntax error is because of the "or", having a second if statement embedded in the first one, or what. It seems to start showing up when I add the first "{"&lt;/P&gt;&lt;P&gt;My destination field is a Singleline text, and I'm trying to do this in the calculation. Not opposed to switching to Connect and doing it on the XLS.&lt;/P&gt;&lt;P&gt;Anyone have ideas&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 19:34:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/calculate-field-based-on-previous-dropdown/m-p/1192320#M43738</guid>
      <dc:creator>agettinger_mdph_opem</dc:creator>
      <dc:date>2022-07-14T19:34:58Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate field based on previous dropdown question in survey</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/calculate-field-based-on-previous-dropdown/m-p/1192336#M43739</link>
      <description>&lt;P&gt;In Survey123, the&amp;nbsp;&lt;STRONG&gt;if&lt;/STRONG&gt; function follows the syntax&lt;/P&gt;&lt;PRE&gt;if(condition, return if true, return if false)&lt;/PRE&gt;&lt;P&gt;So, for the example expression you give, you'd need to write this out as follows (I'll use line breaks to make this clearer):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if(
    ${hospital} == 'Facility1' or ${hospital} == 'Facility2',
    'Region 1',
    if(
        $[hospital} == 'Facility3' or ${hospital} == 'Facility4' or ${hospital} == 'Facility5',
        Region 2',
        ''
    )
)
&lt;/LI-CODE&gt;&lt;P&gt;You'll need that all in one line for it to work properly, but note how multiple conditions have to be specified clearly. It feels linguistically sensible to say "${hospital} = 'A' or 'B', but programmatically, your survey is going to treat 'B' as its own condition.&lt;/P&gt;&lt;P&gt;For a large number of potential hospitals and regions, this can make for a&amp;nbsp;&lt;EM&gt;large&lt;/EM&gt; expression, but at least you'll only need to write it once.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Jul 2022 20:49:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/calculate-field-based-on-previous-dropdown/m-p/1192336#M43739</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-07-14T20:49:57Z</dc:date>
    </item>
  </channel>
</rss>

