<?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: Reproducing Labelling SQL Query as Arcade Label expression in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150156#M52286</link>
    <description>&lt;P&gt;Is there a reason not to simply use SQL? If you're in ArcGIS Pro, you can write your filters in SQL without issue.&lt;/P&gt;&lt;P&gt;You mention you're using the "when" function. What's the rest of your expression look like?&lt;/P&gt;</description>
    <pubDate>Thu, 03 Mar 2022 13:46:32 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2022-03-03T13:46:32Z</dc:date>
    <item>
      <title>Reproducing Labelling SQL Query as Arcade Label expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150025#M52275</link>
      <description>&lt;P&gt;Trying to simplify the number of label classes . So I'm trying to set the expressions used in the&amp;nbsp;When logical function by replicating the SQL Quaries previously used to distinguish between label classes.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But I'm struggling to replicate this one&lt;/P&gt;&lt;BLOCKQUOTE&gt;&lt;P&gt;FEATURETYPE &amp;nbsp;= &amp;nbsp;&amp;nbsp;'Railway' And STATUS = 'Operational' And OWNER NOT IN ('Private', 'Aurizon') AND ROUTENAME NOT LIKE '%System' AND ROUTENAME NOT LIKE '%Yard' AND ROUTENAME NOT LIKE '%Siding'&lt;/P&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;I know wildcards are a bit tricky in Arcade which is where I'm getting stuck.&lt;/P&gt;&lt;P&gt;Any help would be appreciated.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 01:19:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150025#M52275</guid>
      <dc:creator>MattSmithCarto</dc:creator>
      <dc:date>2022-03-03T01:19:10Z</dc:date>
    </item>
    <item>
      <title>Re: Reproducing Labelling SQL Query as Arcade Label expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150156#M52286</link>
      <description>&lt;P&gt;Is there a reason not to simply use SQL? If you're in ArcGIS Pro, you can write your filters in SQL without issue.&lt;/P&gt;&lt;P&gt;You mention you're using the "when" function. What's the rest of your expression look like?&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 13:46:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150156#M52286</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-03T13:46:32Z</dc:date>
    </item>
    <item>
      <title>Re: Reproducing Labelling SQL Query as Arcade Label expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150203#M52297</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-online-questions/like-function-in-arcade/td-p/344889" target="_self"&gt;This post might help.&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 15:20:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150203#M52297</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2022-03-03T15:20:31Z</dc:date>
    </item>
    <item>
      <title>Re: Reproducing Labelling SQL Query as Arcade Label expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150476#M52338</link>
      <description>&lt;P&gt;I actually haven't written it yet - I got caught by the first expression/result couplet which is the most complicated. So I can't really post that yet. We are trying to stick with Arcade as our language where possible.&lt;/P&gt;&lt;P&gt;The reason of trying to move away from seprate label classes defined by SQL is that I'm preparing a vector tile basemap that my organisation will then leverage to turn into different flavours using the vector tile editor or editing the JSON.&lt;/P&gt;&lt;P&gt;The idea is to minimise the number of layers that need to be re-symbolised by combining what would've been several label classes into one. These label classes have the same symbology but have a different output string depending on their operational status. So an active railway line would be labelled "Main Line", but an abandoned line would be labelled "Silver Spur Branch (Abandoned)" , a dismantled line "Brisbane Valley Line (dismantled)" and so on. But we don't need label classes in the vector tile package for each of them. ...If that makes sense...&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 23:12:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150476#M52338</guid>
      <dc:creator>MattSmithCarto</dc:creator>
      <dc:date>2022-03-03T23:12:59Z</dc:date>
    </item>
    <item>
      <title>Re: Reproducing Labelling SQL Query as Arcade Label expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150478#M52339</link>
      <description>&lt;P&gt;Thanks, yes I had seen that thread, but none of solutions proposed worked for me.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 23:14:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150478#M52339</guid>
      <dc:creator>MattSmithCarto</dc:creator>
      <dc:date>2022-03-03T23:14:37Z</dc:date>
    </item>
    <item>
      <title>Re: Reproducing Labelling SQL Query as Arcade Label expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150485#M52341</link>
      <description>&lt;P&gt;Sorry, thought I posted a different link that used the Includes function in leu of "IN" but can't find that one right now and headed out for the weekend.&lt;/P&gt;&lt;P&gt;Something like this is what I was thinking for replacing the "IN" function, then the link I provided you could extract the "LIKE" equivalent.&amp;nbsp; Putting the ! (as below) means NOT IN, remove it for IN.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;var field= $feature.MUTCDcode;
var arr = ["R1-1", "R2-1(25)", "R3-1", "R3-5R", "R3-8(Mod)", "R8-3(FL)",
           "W11-2", "W16-7PL", "W16-7PR", "D3-1", "D3-1(HS)", "D3-1(RB)",
           "D3-1(OH)", "D9-2", "M5-1L", "S3-1", "R3-17"];

!Includes(arr, field);&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so for this one, anything not in the list (arr) returns True.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Thu, 03 Mar 2022 23:36:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150485#M52341</guid>
      <dc:creator>RichlandGIS</dc:creator>
      <dc:date>2022-03-03T23:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Reproducing Labelling SQL Query as Arcade Label expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150493#M52343</link>
      <description>&lt;P&gt;Ah, I see. You want the label expression to dynamically pipe in different values.&lt;/P&gt;&lt;P&gt;IN basically equates to the &lt;STRONG&gt;Includes &lt;/STRONG&gt;function. Checking for an "ends with" is a bit trickier without wildcards, but we can do it by grabbing the &lt;STRONG&gt;Right&lt;/STRONG&gt; portion of a string equal to the length of the searched text, and see if it's equal to the searched text. To put that in code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// a test string
var str = 'Here\'s a sample'

// this returns true
Right(str, 5) == 'ample'

// this returns false
Right(str, 5) == 'fishy'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We can actually build our own custom function for this. Let's call it &lt;STRONG&gt;EndsWith&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;Okay, maybe it would look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var bad_names = [
    'Private',
    'Aurizon'
]

// Custom function returns boolean if searchText is at the end of text
function EndsWith(searchText, text){
    
    // Get length of search text
    var strlen = Count(searchText)
    
    // Look at end of text for that string
    return(Right(text, strlen) == searchText)
}

var f = $feature['FEATURETYPE']
var s = $feature['STATUS']
var o = $feature['OWNER']
var r = $feature['ROUTENAME']

if( f == 'Railway' &amp;amp;&amp;amp;
    s == 'Operational' &amp;amp;&amp;amp;
    Includes(bad_names, o) &amp;amp;&amp;amp;
    !EndsWith('Yard', r) &amp;amp;&amp;amp;
    !EndsWith('Siding', r) &amp;amp;&amp;amp;
    !EndsWith('System', r)
    ) {
        return 'Some Category'
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Now, I notice that all your conditions must be true, since these are all "AND" statements in the original SQL.&lt;/P&gt;&lt;P&gt;Depending on where you're working, and what version Arcade you have access to, you might try using the &lt;STRONG&gt;All &lt;/STRONG&gt;function. Try this instead of lines 21 - 29 of the expression above.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var conditions = [
    f == 'Railway',
    s == 'Operational',
    Includes(bad_names, o),
    !EndsWith('Yard', r),
    !EndsWith('Siding', r),
    !EndsWith('System', r)
]
    
if( All(conditions, Boolean)){
    return 'Some Category'
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;That would allow you to establish all your conditions prior to the if/else section, which can help make your expression more readable.&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 00:19:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1150493#M52343</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-03-04T00:19:39Z</dc:date>
    </item>
    <item>
      <title>Re: Reproducing Labelling SQL Query as Arcade Label expression</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1187559#M56702</link>
      <description>&lt;P&gt;Realised I hadn't replied to this. Thanks very much Josh. Exactly what I needed.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 22:00:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/reproducing-labelling-sql-query-as-arcade-label/m-p/1187559#M56702</guid>
      <dc:creator>MattSmithCarto</dc:creator>
      <dc:date>2022-06-28T22:00:52Z</dc:date>
    </item>
  </channel>
</rss>

