<?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: If then statement for a calculated value. in ArcGIS Survey123 Questions</title>
    <link>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1040322#M33390</link>
    <description>&lt;P&gt;James, I have a like challenge, and I have tried to follow the example, but I keep getting denied.&amp;nbsp; Can you take a look and let me know what is askew?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working in s123 arcgis connect &amp;gt; xlsx file &amp;gt; calculate field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;lt;= 18.5, 'Ephemeral',&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;gt;= 18.5 and ${total_points}&amp;lt;= 29.5, 'Intermittent',&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;gt;= 30), 'Perennial')))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the xlsx just in case, record 19 is where I am trying to plug in the formula.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate the consideration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers, Will&lt;/P&gt;</description>
    <pubDate>Wed, 24 Mar 2021 18:58:08 GMT</pubDate>
    <dc:creator>ChrisR_</dc:creator>
    <dc:date>2021-03-24T18:58:08Z</dc:date>
    <item>
      <title>If then statement for a calculated value.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1030910#M32780</link>
      <description>&lt;P&gt;I'm trying to convert wind direction from degrees to compass. I have a calculated wind direction value, but I want to be able to classify it as compass direction instead of the degree as a field in Survey123. These are the compass categories I would like the value to fall into. I know I have to write an if-then statement in the calculation column, but I am having a heck of a time wrapping my head around the syntax. Please help!&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;N = North (349 - 011 degrees)&lt;/LI&gt;&lt;LI&gt;NNE = North-Northeast (012-033 degrees)&lt;/LI&gt;&lt;LI&gt;NE = Northeast (034-056 degrees)&lt;/LI&gt;&lt;LI&gt;ENE = East-Northeast (057-078 degrees)&lt;/LI&gt;&lt;LI&gt;E = East (079-101 degrees)&lt;/LI&gt;&lt;LI&gt;ESE = East-Southeast (102-123 degrees)&lt;/LI&gt;&lt;LI&gt;SE = Southeast (124-146 degrees)&lt;/LI&gt;&lt;LI&gt;SSE = South-Southeast (147-168 degrees)&lt;/LI&gt;&lt;LI&gt;S = South (169-191 degrees)&lt;/LI&gt;&lt;LI&gt;SSW = South-Southwest (192-213 degrees)&lt;/LI&gt;&lt;LI&gt;SW = Southwest (214-236 degrees)&lt;/LI&gt;&lt;LI&gt;WSW = West-Southwest (237-258 degrees)&lt;/LI&gt;&lt;LI&gt;W = West (259-281 degrees)&lt;/LI&gt;&lt;LI&gt;WNW = West-Northwest (282-303 degrees)&lt;/LI&gt;&lt;LI&gt;NW = Northwest (304-326 degrees)&lt;/LI&gt;&lt;LI&gt;NNW = North-Northwest (327-348 degrees)&lt;/LI&gt;&lt;/UL&gt;</description>
      <pubDate>Fri, 26 Feb 2021 09:08:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1030910#M32780</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-26T09:08:49Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement for a calculated value.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1030953#M32781</link>
      <description>&lt;P&gt;It would be an absolute bear of a calculation formula to nest all those ifs, but it's doable. I would first want to know what the intended end use of the classified "direction" attribute is, though. It might be possible to have this as an expression evaluating on the fly using Arcade, depending on where you're using the information.&lt;/P&gt;&lt;P&gt;But to do it in Survey123, you just need to keep track of your parenthesis. Here's part of the code broken up and formatted nicely so you can see what's going on a little easier. Basically, just write each range in its own if, then at the very end include a '' for the final "else", then a close parenthesis for each if statement.&lt;/P&gt;&lt;P&gt;Also, since N spans the 0-line, its statement looks different from the rest&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;if(${bearing} &amp;lt; 12) or ${bearing} &amp;gt;= 349, 'N',
if(${bearing} &amp;gt;=12 and ${bearing} &amp;lt; 34, 'NNE',
if(${bearing} &amp;gt;=34 and ${bearing} &amp;lt; 57, 'NE',
if(${bearing} &amp;gt;= 57 and ${bearing} &amp;lt; 79, 'ENE',
''))))&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;In Survey, this'll need to be all on one line, but it should work.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1614347892617.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7048iE0B1CD2237686DD0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1614347892617.png" alt="jcarlson_0-1614347892617.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;H4&gt;Alternate Approach: Concatenate Separate Ifs&lt;/H4&gt;&lt;P&gt;It occurs to me that there is a way to cut the number of statements in half. If we were to draw out the compass, it might look like this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_1-1614348939323.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/7053iC19C1816124588A8/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_1-1614348939323.png" alt="jcarlson_1-1614348939323.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If we evaluate the major cardinal directions separately, then concatenate them to an evaluation of the diagonals, we can get all 16 possible combinations with only 8 ifs. I won't type them all out, but here's a brief portion to give you an idea.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;concat(
    if(${bearing} &amp;lt;= 33 or ${bearing} &amp;gt;= 327, 'N',
    if(${bearing} &amp;gt;= 57 and ${bearing} &amp;lt;= 123, 'E',
    '')),
    if(${bearing} &amp;gt;= 12 and ${bearing} &amp;lt;= 78, 'NE',
    if(${bearing} &amp;gt;= 102 and ${bearing} &amp;lt;= 168, 'SE',
    ''))
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;In those areas where the major direction "wedge" intersects with the diagonal "wedge", you'll end up with values like "NNE" or "WSW". In areas where they do not, the empty string will be returned from one or the other if statement, and you'll get "N" or "SE".&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 14:25:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1030953#M32781</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-02-26T14:25:20Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement for a calculated value.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1031038#M32786</link>
      <description>&lt;P&gt;Hi @Anonymous User&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/363906"&gt;@jcarlson&lt;/a&gt;'s solutions are very good.&amp;nbsp; I might suggest 1 small tweak:&lt;/P&gt;&lt;P&gt;You should only need less than/less than or equal comparaisons for the first (16 if statements) solution; you can account for the wrap (large values being the same as smaller ones) by using the same value as the final 'if false' value.&amp;nbsp; As an example for the 4 directions (the splits at 45 degrees):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if(${bearing} &amp;lt;= 45, 'N',
    if(${bearing} &amp;lt;= 135, 'E',
        if(${bearing} &amp;lt;= 225, 'S',
            if(${bearing} &amp;lt;= 315, 'W','N')
        )
    )
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 17:17:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1031038#M32786</guid>
      <dc:creator>JamesTedrick</dc:creator>
      <dc:date>2021-02-26T17:17:37Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement for a calculated value.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1031131#M32788</link>
      <description>&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Fri, 26 Feb 2021 20:30:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1031131#M32788</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-02-26T20:30:26Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement for a calculated value.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1031513#M32812</link>
      <description>&lt;P&gt;Another idea is to have a csv with rows 0-360 then use pulldata to go get the value.&amp;nbsp; Easier to write and easy to make with excel autofill.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Mar 2021 15:14:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1031513#M32812</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2021-03-01T15:14:28Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement for a calculated value.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1040322#M33390</link>
      <description>&lt;P&gt;James, I have a like challenge, and I have tried to follow the example, but I keep getting denied.&amp;nbsp; Can you take a look and let me know what is askew?&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working in s123 arcgis connect &amp;gt; xlsx file &amp;gt; calculate field.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;lt;= 18.5, 'Ephemeral',&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;gt;= 18.5 and ${total_points}&amp;lt;= 29.5, 'Intermittent',&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;gt;= 30), 'Perennial')))&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have attached the xlsx just in case, record 19 is where I am trying to plug in the formula.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Appreciate the consideration.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Cheers, Will&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 18:58:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1040322#M33390</guid>
      <dc:creator>ChrisR_</dc:creator>
      <dc:date>2021-03-24T18:58:08Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement for a calculated value.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1040349#M33392</link>
      <description>&lt;P&gt;You missed the last else.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;lt;= 18.5, 'Ephemeral',&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;gt;= 18.5 and ${total_points}&amp;lt;= 29.5, 'Intermittent',&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;gt;= 30), 'Perennial', "Missing this one')))&lt;/P&gt;&lt;P&gt;But If you want all values &amp;gt; 30 on the last one then no need for the last if though anyway&lt;/P&gt;&lt;P&gt;if(${total_points} &amp;lt;= 18.5, 'Ephemeral', if(${total_points} &amp;gt;= 18.5 and ${total_points} &amp;lt;= 29.5, 'Intermittent', 'Perennial'))&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 19:56:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1040349#M33392</guid>
      <dc:creator>DougBrowning</dc:creator>
      <dc:date>2021-03-24T19:56:14Z</dc:date>
    </item>
    <item>
      <title>Re: If then statement for a calculated value.</title>
      <link>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1040351#M33393</link>
      <description>&lt;P&gt;very much thanks, your kung fu is unbeatable!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;shalom, will&lt;/P&gt;</description>
      <pubDate>Wed, 24 Mar 2021 20:01:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-survey123-questions/if-then-statement-for-a-calculated-value/m-p/1040351#M33393</guid>
      <dc:creator>ChrisR_</dc:creator>
      <dc:date>2021-03-24T20:01:44Z</dc:date>
    </item>
  </channel>
</rss>

