<?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: Nested If or When Statement in Arcade Needs Boolean Test Condition in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/nested-if-or-when-statement-in-arcade-needs/m-p/1151262#M52458</link>
    <description>&lt;P&gt;Aha!&amp;nbsp; It's the "==" vs "=" that was tripping me up!&amp;nbsp; Thank you for the great explanation and the streamlining of the code.&amp;nbsp; It works perfectly now!&lt;/P&gt;</description>
    <pubDate>Mon, 07 Mar 2022 14:27:53 GMT</pubDate>
    <dc:creator>SummerKing</dc:creator>
    <dc:date>2022-03-07T14:27:53Z</dc:date>
    <item>
      <title>Nested If or When Statement in Arcade Needs Boolean Test Condition</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/nested-if-or-when-statement-in-arcade-needs/m-p/1150955#M52409</link>
      <description>&lt;P&gt;Testing this in the Arcade Playground, the error that occurs happens whether I use an IF or a WHEN statement.&lt;/P&gt;&lt;P&gt;The goal is to round up if the number is &amp;gt;= x.75, round down is the number is &amp;lt; x.75 and not to round at all if the number is x.00.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Code:&lt;/P&gt;&lt;P&gt;//Some variables instead of referencing geodatabase fields which Playground doesn't understand.&lt;BR /&gt;&lt;BR /&gt;var Life80=5.5&lt;BR /&gt;var LSY=2020&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;//Determine if date is before or after FY start of September 1&lt;BR /&gt;Var RoundDown = Floor(Life80,0);&lt;/P&gt;&lt;P&gt;//Additions to simplify formula&lt;BR /&gt;Var StraightAdd = Round(LSY+Life80,0);&lt;BR /&gt;Var AddRound = LSY+RoundDown;&lt;/P&gt;&lt;P&gt;//Constrain to current year minimum and ridiculously later year maximum&lt;BR /&gt;Iif((Life80=RoundDown), StraightAdd, (Iif((Life80-0.75)&amp;lt;RoundDown, Constrain(AddRound,2022,9999), Constrain(StraightAdd, 2022,9999))));&lt;/P&gt;&lt;P&gt;//Alternate expression: When(Life80=RoundDown, StraightAdd, (Life80-0.75)&amp;lt;RoundDown, Constrain(AddRound,2022,9999), (Life80-0.75)&amp;gt;RoundDown, Constrain(StraightAdd, 2022,9999),9999);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Execution Error:&lt;/SPAN&gt;&lt;SPAN&gt;IF Function must have a boolean test condition&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Question: Is there something off about my syntax?&amp;nbsp; Have been looking through the ESRI community and have seen multiple examples of IF and WHEN statements and the syntax is just as above as far as I can tell.&amp;nbsp; I feel as if I'm missing something really obvious, but I don't see it.&amp;nbsp; Any insight would be appreciated!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 23:32:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/nested-if-or-when-statement-in-arcade-needs/m-p/1150955#M52409</guid>
      <dc:creator>SummerKing</dc:creator>
      <dc:date>2022-03-04T23:32:30Z</dc:date>
    </item>
    <item>
      <title>Re: Nested If or When Statement in Arcade Needs Boolean Test Condition</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/nested-if-or-when-statement-in-arcade-needs/m-p/1150973#M52412</link>
      <description>&lt;P&gt;Try a similar expression.&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;var ar=$feature.Area_Feet
IIF(ar-Floor(ar,0)&amp;gt;=0.75,Ceil(ar,0),Floor(ar,0))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JayantaPoddar_0-1646448599763.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35688iCE73878C2B353F71/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JayantaPoddar_0-1646448599763.png" alt="JayantaPoddar_0-1646448599763.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Mar 2022 02:50:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/nested-if-or-when-statement-in-arcade-needs/m-p/1150973#M52412</guid>
      <dc:creator>JayantaPoddar</dc:creator>
      <dc:date>2022-03-05T02:50:27Z</dc:date>
    </item>
    <item>
      <title>Re: Nested If or When Statement in Arcade Needs Boolean Test Condition</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/nested-if-or-when-statement-in-arcade-needs/m-p/1151016#M52420</link>
      <description>&lt;P&gt;The &lt;STRONG&gt;Iif &lt;/STRONG&gt;function certainly has its place, but nesting more than one of them makes for hard-to-read code. Consider just breaking it out into separate if/else if/else blocks.&lt;/P&gt;&lt;P&gt;PS - Don't forget about the "insert/edit code sample" button here!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1646511965896.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35695i334C113FD11CB44B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1646511965896.png" alt="jcarlson_0-1646511965896.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Anyway, testing your same expression in the Playground. The first thing I notice is this:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;Life80=RoundDown&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;In Arcade, this would set the Life80 variable to the value in the RoundDown variable. To check equivalence, you need to use "==". In fact, making that single change gets your expression to evaluate!&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_1-1646512142199.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35696i75524343D28CE58F/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_1-1646512142199.png" alt="jcarlson_1-1646512142199.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;But here's that long nested iif, broken up:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (Life80 == RoundDown){
    return StraightAdd
} else if (Life80-0.75 &amp;lt; RoundDown){
    return Constrain(AddRound,2022,9999)
} else {
    return Constrain(StraightAdd, 2022,9999)
}&lt;/LI-CODE&gt;&lt;P&gt;As you allude to in your post, though, you could certainly do this with &lt;STRONG&gt;When&lt;/STRONG&gt;. In your particular situation, it makes sense to use that, as it will be more concise. A full if/else if/else block is useful when the different conditions merely cause your expression to branch off, but since we're just determining the final returned value, it's a bit much. Here's the &lt;STRONG&gt;when &lt;/STRONG&gt;version:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;return When(
    Life80 == RoundDown, StraightAdd,
    Life80 - 0.75 &amp;lt; RoundDown, Constrain(AddRound, 2022, 9999),
    Constrain(StraightAdd, 2022, 9999)
)&lt;/LI-CODE&gt;</description>
      <pubDate>Sat, 05 Mar 2022 20:36:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/nested-if-or-when-statement-in-arcade-needs/m-p/1151016#M52420</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-05T20:36:34Z</dc:date>
    </item>
    <item>
      <title>Re: Nested If or When Statement in Arcade Needs Boolean Test Condition</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/nested-if-or-when-statement-in-arcade-needs/m-p/1151262#M52458</link>
      <description>&lt;P&gt;Aha!&amp;nbsp; It's the "==" vs "=" that was tripping me up!&amp;nbsp; Thank you for the great explanation and the streamlining of the code.&amp;nbsp; It works perfectly now!&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 14:27:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/nested-if-or-when-statement-in-arcade-needs/m-p/1151262#M52458</guid>
      <dc:creator>SummerKing</dc:creator>
      <dc:date>2022-03-07T14:27:53Z</dc:date>
    </item>
  </channel>
</rss>

