<?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 Multiple IF Statements from different fields in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/multiple-if-statements-from-different-fields/m-p/1189642#M46811</link>
    <description>&lt;P&gt;Hello, I'm trying to write 1 arcade expression.&amp;nbsp; In my table I have a field for Sunday; Monday; Tuesday; etc.&amp;nbsp; The data is either a 1 if a work crew is at that location on that day or a 0 if they are not.&lt;/P&gt;&lt;P&gt;I want my expression to list the days of the week they are at each location but I'm only able to return the first instance with my formulas.&lt;/P&gt;&lt;P&gt;I tried and IF and Else IF statement&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;if($feature["USER_SUNDAY"] == 1)&lt;BR /&gt;{return " Su "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_MONDAY"] == 1)&lt;BR /&gt;{return " M "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_TUESDAY"] == 1)&lt;BR /&gt;{return " Tu "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_WEDNESDAY"] == 1)&lt;BR /&gt;{return " W "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_THURSDAY"] == 1)&lt;BR /&gt;{return " Th "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_FRIDAY"] == 1)&lt;BR /&gt;{return " F "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_SATURDAY"] == 1)&lt;BR /&gt;{return " Sa "}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And also tried a nested statement:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;iif($feature["USER_SUNDAY"] == 1,'Su',&lt;BR /&gt;iif($feature["USER_MONDAY"] == 1,'M',&lt;BR /&gt;iif($feature["USER_TUESDAY"] == 1,'Tu',&lt;BR /&gt;iif($feature["USER_WEDNESDAY"] == 1,'W',&lt;BR /&gt;iif($feature["USER_THURSDAY"] == 1,'Th',&lt;BR /&gt;iif($feature["USER_FRIDAY"] == 1,'F',&lt;BR /&gt;iif($feature["USER_SATURDAY"] == 1,'Sa',NONE)))))))&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I even tried replacing IIF with When but achieved the same result.&amp;nbsp; The formulas only return the first day a crew is at a location and won't combine the days if they are there more than once in the PopUp.&lt;/P&gt;&lt;P&gt;Is this possible or do I need to create an expression for each day of the week and then add it to my PopUp?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Tue, 05 Jul 2022 21:54:31 GMT</pubDate>
    <dc:creator>David-Semitekol</dc:creator>
    <dc:date>2022-07-05T21:54:31Z</dc:date>
    <item>
      <title>Multiple IF Statements from different fields</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/multiple-if-statements-from-different-fields/m-p/1189642#M46811</link>
      <description>&lt;P&gt;Hello, I'm trying to write 1 arcade expression.&amp;nbsp; In my table I have a field for Sunday; Monday; Tuesday; etc.&amp;nbsp; The data is either a 1 if a work crew is at that location on that day or a 0 if they are not.&lt;/P&gt;&lt;P&gt;I want my expression to list the days of the week they are at each location but I'm only able to return the first instance with my formulas.&lt;/P&gt;&lt;P&gt;I tried and IF and Else IF statement&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;if($feature["USER_SUNDAY"] == 1)&lt;BR /&gt;{return " Su "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_MONDAY"] == 1)&lt;BR /&gt;{return " M "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_TUESDAY"] == 1)&lt;BR /&gt;{return " Tu "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_WEDNESDAY"] == 1)&lt;BR /&gt;{return " W "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_THURSDAY"] == 1)&lt;BR /&gt;{return " Th "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_FRIDAY"] == 1)&lt;BR /&gt;{return " F "}&lt;/P&gt;&lt;P&gt;else if($feature["USER_SATURDAY"] == 1)&lt;BR /&gt;{return " Sa "}&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;And also tried a nested statement:&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;iif($feature["USER_SUNDAY"] == 1,'Su',&lt;BR /&gt;iif($feature["USER_MONDAY"] == 1,'M',&lt;BR /&gt;iif($feature["USER_TUESDAY"] == 1,'Tu',&lt;BR /&gt;iif($feature["USER_WEDNESDAY"] == 1,'W',&lt;BR /&gt;iif($feature["USER_THURSDAY"] == 1,'Th',&lt;BR /&gt;iif($feature["USER_FRIDAY"] == 1,'F',&lt;BR /&gt;iif($feature["USER_SATURDAY"] == 1,'Sa',NONE)))))))&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I even tried replacing IIF with When but achieved the same result.&amp;nbsp; The formulas only return the first day a crew is at a location and won't combine the days if they are there more than once in the PopUp.&lt;/P&gt;&lt;P&gt;Is this possible or do I need to create an expression for each day of the week and then add it to my PopUp?&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Tue, 05 Jul 2022 21:54:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/multiple-if-statements-from-different-fields/m-p/1189642#M46811</guid>
      <dc:creator>David-Semitekol</dc:creator>
      <dc:date>2022-07-05T21:54:31Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple IF Statements from different fields</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/multiple-if-statements-from-different-fields/m-p/1189717#M46814</link>
      <description>&lt;P&gt;When you return from a function (or an Arcade expression in this case), the code stops executing there. Everything after the first executed return statement gets skipped. That's why your first example didn't work.&lt;/P&gt;&lt;P&gt;It's also why your second example didn't work, because it can be rewritten like this:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if(condition1){
    return "Su"
} else {
    if(condition2) {
        return "Mo"
    } else {
        if(condition3) {
            return "Tu"
        } else {
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;To do what you want:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;evaluate an if statement for each condition&lt;/LI&gt;&lt;LI&gt;either build up a return string as you go along or store each string and concatenate at the end&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;// array to store the strings
var open_days = []

// evaluate each day, add open days to the array
if($feature.USER_SUNDAY == 1) { Push(open_days, "Su") }
if($feature.USER_MONDAY == 1) { Push(open_days, "M") }
if($feature.USER_TUESDAY == 1) { Push(open_days, "Tu") }
if($feature.USER_WEDNESDAY == 1) { Push(open_days, "W") }
if($feature.USER_THURSDAY == 1) { Push(open_days, "Th") }
if($feature.USER_FRIDAY == 1) { Push(open_days, "F") }
if($feature.USER_SATURDAY == 1) { Push(open_days, "Sa") }

// concatenate the strings and return
return Concatenate(open_days, ", ")&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 06 Jul 2022 07:04:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/multiple-if-statements-from-different-fields/m-p/1189717#M46814</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-07-06T07:04:08Z</dc:date>
    </item>
    <item>
      <title>Re: Multiple IF Statements from different fields</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/multiple-if-statements-from-different-fields/m-p/1189924#M46827</link>
      <description>&lt;P&gt;Thanks Johannes, your solution code worked perfectly.&amp;nbsp; Just to make sure I learned and not just copied:&lt;/P&gt;&lt;P&gt;You assign a variable, in this case it is open_days and the = [] allows you to add to it later in the formula?&lt;/P&gt;&lt;P&gt;The Push command takes the output from the If statement and adds it to the variable.&lt;/P&gt;&lt;P&gt;At the end you are Returning the values from the If statements and adding a comma to the output for readability.&lt;/P&gt;&lt;P&gt;This was awesome, thank you again!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Jul 2022 15:35:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/multiple-if-statements-from-different-fields/m-p/1189924#M46827</guid>
      <dc:creator>David-Semitekol</dc:creator>
      <dc:date>2022-07-06T15:35:34Z</dc:date>
    </item>
  </channel>
</rss>

