<?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/concatenate depending on field  values in Attribute Rules Questions</title>
    <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249189#M706</link>
    <description>&lt;P&gt;In line 12, you need to use the route field (the value that is already in the table, not the concatenated value you are calculating). You changed the variable name to &lt;EM&gt;routename&lt;/EM&gt;, use that in line 13, too!&lt;/P&gt;&lt;P&gt;As Mike said, Count gives an error for null. Try replacing line 1 with this (this is the same null check that we already do for the week):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var prefix = IIf(
    IsEmpty($feature.CASTERBOXCARDBOARD_PREFIX),
    "",
    $feature.CASTERBOXCARDBOARD_PREFIX
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Jan 2023 18:57:42 GMT</pubDate>
    <dc:creator>JohannesLindner</dc:creator>
    <dc:date>2023-01-18T18:57:42Z</dc:date>
    <item>
      <title>Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1248927#M699</link>
      <description>&lt;P&gt;Hello-&lt;/P&gt;&lt;P&gt;I am trying to write an attribute rule that will calculate a field value by concatenating other fields. I have the basic arcade written, however, we have some variation in our table that could cause the straightforward statements to not work as I want. Here is what I need:&lt;/P&gt;&lt;P&gt;Prefix + Route + Week -- the field can only be 5 characters long total -- ex CC01S or D005N or CB005 or D0005&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Prefix could be one or two characters, ex: CC, D, CB&lt;/LI&gt;&lt;LI&gt;Route has a value like 001, 005, 011&lt;/LI&gt;&lt;LI&gt;Week = North or South-- I amusing the following to pull off only the first letter of the word:&amp;nbsp;LEFT($feature.COMMERCIAL_WEEK,1)&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;My thought is that if I can identify whether or not the following is true I can create the new concatenated field:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Identify if Week is null. THIS WORKS&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="javascript"&gt;// First determine if there is week information
// If there is, add 'week' sufix to it
var wmWeek = null;
if (!IsEmpty($feature.CASTERBOXCARDBOARD_WEEK)){
  wmWeek = LEFT($feature.CASTERBOXCARDBOARD_WEEK,1);
}&lt;/LI-CODE&gt;&lt;UL&gt;&lt;LI&gt;Identify if prefix value is one or two characters long. This would allow me to know how many leading zeros are needed from the route field. This is also the step where I get stuck. What I need to be able to write is something like:&lt;UL&gt;&lt;LI&gt;IF Prefix is &amp;gt;1 return Route =&amp;nbsp;RIGHT($feature.Route,2)&lt;/LI&gt;&lt;LI&gt;else IF Prefix is &amp;lt;1 return Route = RIGHT($feature.route,1)&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Here is what I have working so far thanks to a couple of blog posts I found:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//works, getting closer- need to figure out the prefix when 2 characters and the route 0001 vs 001 vs 01

// First determine if there is week information
// If there is, add 'week' sufix to it
var wmWeek = null;
if (!IsEmpty($feature.CASTERBOXCARDBOARD_WEEK)){
  wmWeek = LEFT($feature.CASTERBOXCARDBOARD_WEEK,1);
}

//Second determin if the prefix is one or two characters
var prefix = $feature.CASTERBOXCARDBOARD_PREFIX
var route = $feature.CASTERBOXCARDBOARD_ROUTE

if (prefix is &amp;gt;1){

}
//List of fields to combine
var parts =[$feature.CASTERBOXCARDBOARD_PREFIX,$feature.CASTERBOXCARDBOARD_ROUTE,wmWeek];

//loop through parts, if null/empty add to new array
var filteredparts =[];
for (var i in parts) {
var value = parts[i];
if (isEmpty(value)) continue;
filteredparts[Count(filteredparts)] =value
}
//Concatenate
return concatenate(filteredparts,"");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;any help or ideas here would be great!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 00:40:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1248927#M699</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2023-01-18T00:40:14Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1248931#M700</link>
      <description>&lt;P&gt;You can get the length of a string with the&amp;nbsp;&lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#count" target="_blank" rel="noopener"&gt;COUNT&lt;/A&gt;&amp;nbsp;function, then you can use that length to pick which branch to take.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 00:44:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1248931#M700</guid>
      <dc:creator>DavidSolari</dc:creator>
      <dc:date>2023-01-18T00:44:48Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1248970#M701</link>
      <description>&lt;P&gt;Does this do what you want?&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var prefix = $feature.CASTERBOXCARDBOARD_PREFIX
var week = IIf(
    IsEmpty($feature.CASTERBOXCARDBOARD_WEEK),
    "",
    Left($feature.CASTERBOXCARDBOARD_WEEK, 1)
    )
var route_length = 5 - Count(prefix) - Count(week)
var route = Right($feature.CASTERBOXCARDBOARD_ROUTE, route_length)
return Concatenate([prefix, route, week])&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 18 Jan 2023 07:12:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1248970#M701</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-18T07:12:53Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249150#M703</link>
      <description>&lt;P&gt;thank you for the response!&amp;nbsp; I think this is getting me closer... but I am getting an &lt;EM&gt;Invalid expression. Error on line 10. Expected array or feature set.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I adjusted what you shared above a bit, I needed the ROUTENAME field to be the 5 character limit. I am not sure if I have line 12 correct. should it be the route field (values of 001, 005 etc) or the Route Name (concatenated calculation field)?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//prefix + route + week
var prefix = $feature.CASTERBOXCARDBOARD_PREFIX
// figure out if wmWeek is null or not so we know if we need to account for N/S in the concatenation or not
var week = IIf(
    IsEmpty($feature.CASTERBOXCARDBOARD_WEEK),
    "",
    Left($feature.CASTERBOXCARDBOARD_WEEK, 1)
    )
//find the length of the routename - 5 character limit - prefix characters - wmWeek character if present
var routename_length = 5 - Count(prefix) - Count(week)
//creates the concatenation
var routename = Right($feature.CASTERBOXCARDBOARD_ROUTE, routename_length)
return Concatenate([prefix, route, week])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;thoughts on how to fix the Expected array or feature set error?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 17:34:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249150#M703</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2023-01-18T17:34:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249183#M704</link>
      <description>&lt;P&gt;Could Prefix be None?&amp;nbsp; Count errors on that&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 18:47:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249183#M704</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2023-01-18T18:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249189#M706</link>
      <description>&lt;P&gt;In line 12, you need to use the route field (the value that is already in the table, not the concatenated value you are calculating). You changed the variable name to &lt;EM&gt;routename&lt;/EM&gt;, use that in line 13, too!&lt;/P&gt;&lt;P&gt;As Mike said, Count gives an error for null. Try replacing line 1 with this (this is the same null check that we already do for the week):&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var prefix = IIf(
    IsEmpty($feature.CASTERBOXCARDBOARD_PREFIX),
    "",
    $feature.CASTERBOXCARDBOARD_PREFIX
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Jan 2023 18:57:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249189#M706</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2023-01-18T18:57:42Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249488#M710</link>
      <description>&lt;P&gt;no- prefix can be two characters or one character, but never empty&lt;/P&gt;&lt;P&gt;thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 15:37:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249488#M710</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2023-01-19T15:37:23Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249503#M711</link>
      <description>&lt;P&gt;Actually!!! When I added this in, it worked!!&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 15:46:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249503#M711</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2023-01-19T15:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249504#M712</link>
      <description>&lt;P&gt;Huge thanks to&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;and&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/188597"&gt;@MikeMillerGIS&lt;/a&gt;&amp;nbsp; for helping me get this one going.&lt;/P&gt;&lt;P&gt;Here is my final that works as I needed. again, thank you!&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//---------------------------------------------------------------------
//prefix + route + week
//check for empty prefix values
var prefix = IIf(
    IsEmpty($feature.CASTERBOXCARDBOARD_PREFIX),
    "",
    $feature.CASTERBOXCARDBOARD_PREFIX
    )
// figure out if wmWeek is null so we know if we need to account for N/S in the concatenation character count
var week = IIf(
    IsEmpty($feature.CASTERBOXCARDBOARD_WEEK),
    "",
    Left($feature.CASTERBOXCARDBOARD_WEEK, 1)
    )
//find the length of the routename - 5 character limit - prefix characters - wmWeek character if present
var routename_length = 5 - Count(prefix) - Count(week)
//creates the concatenation
var routename = Right($feature.CASTERBOXCARDBOARD_ROUTE, routename_length)
return Concatenate([prefix, routename, week])&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 19 Jan 2023 15:47:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249504#M712</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2023-01-19T15:47:20Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249508#M713</link>
      <description>&lt;P&gt;Even though your data may enforce that it is either 1 or 2 characters, the validation generates a random record and that may not have the correct values.&amp;nbsp; So it is always safer to code defensively.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Jan 2023 15:49:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1249508#M713</guid>
      <dc:creator>MikeMillerGIS</dc:creator>
      <dc:date>2023-01-19T15:49:41Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate/concatenate depending on field  values</title>
      <link>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1275555#M800</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/144848"&gt;@DonSjoboen&lt;/a&gt;&amp;nbsp; see if this give you any hints!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2023 21:58:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/attribute-rules-questions/calculate-concatenate-depending-on-field-values/m-p/1275555#M800</guid>
      <dc:creator>VanessaSimps</dc:creator>
      <dc:date>2023-04-04T21:58:31Z</dc:date>
    </item>
  </channel>
</rss>

