<?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: How to Use Arcade GroupBy with Top and OrderBy Expressions in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1223508#M6377</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I found this thread while searching for help with using Orderby, however, I'm very new to Arcade and I am not sure where to insert the function. Here is my code that I created already.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;var intersectLayer =Intersects(FeatureSetByName($map, "CAMS Address Points"), $feature)
var feature = FeatureSetByName($map, "CAMS Address Points")
var results = ""
for (var f in intersectLayer){
if (results ==""){
results = f.Number;
} else{
results += ", " + f.Number + iif(f.NumSuffix == '&amp;lt;Null&amp;gt;', ' ', f.NumSuffix);
}
}
return results&lt;/LI-CODE&gt;&lt;P&gt;Basically, I have a parcel and I am trying to list the address points within that parcel.&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
    <pubDate>Wed, 19 Oct 2022 20:54:01 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2022-10-19T20:54:01Z</dc:date>
    <item>
      <title>How to Use Arcade GroupBy with Top and OrderBy Expressions</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060249#M5873</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I am struggling with using the Arcade's GroupBy with the Top and OrderBy Functions.&lt;/P&gt;&lt;P&gt;Basically I have a polygon layer which references and counts the number of features from another point layer, and I want to display in the popup the top 3 attributes based on counts within each polygon.&lt;/P&gt;&lt;P&gt;I have attached a file the arcade expression code I have so far for the polygon layer, however it is not working at moment (nothing being written in the popup). I am trying to get it to count the total number of point features within any given polygon, group by the attribute value of the facility_name field and find the top 3 facilities that have the highest point count&lt;/P&gt;&lt;P&gt;I am looking for the popup to show something like the following when a polygon is selected:&lt;/P&gt;&lt;P&gt;The Top 3 Facilities in this area are:&lt;/P&gt;&lt;P&gt;1. Facility A: 400 Patients&lt;/P&gt;&lt;P&gt;2. Facility B: 200 Patients&lt;/P&gt;&lt;P&gt;3. Facility C: 100 Patients&lt;/P&gt;&lt;P&gt;Greatly appreciate any help or advice with the code.&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Isaac&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 00:57:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060249#M5873</guid>
      <dc:creator>izk_1989</dc:creator>
      <dc:date>2021-05-21T00:57:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to Use Arcade GroupBy with Top and OrderBy Expressions</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060366#M5874</link>
      <description>&lt;P&gt;One thing I noticed is you used the line&lt;/P&gt;&lt;P&gt;var topFacilities = Top(OrderBy(Filter(stats, "facility_name &amp;lt;&amp;gt; ''"),"ClinicCount desc"), 3)&lt;/P&gt;&lt;P&gt;but later loop through a variable you haven't declared&lt;/P&gt;&lt;P&gt;for(var item in topClinics){&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 12:28:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060366#M5874</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2021-05-21T12:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to Use Arcade GroupBy with Top and OrderBy Expressions</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060406#M5875</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/461716"&gt;@izk_1989&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;In addition to what Ken correctly pointed out, there is another error: you don't have a total field, you have&amp;nbsp;ClinicCount. I also formatted the result a bit differently.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Reference the points feature layer
var patientsDA = FeatureSetByName($map,"PointsLayer")

// Count the number of patients within each polygon
var cntPatients = Intersects(patientsDA, $feature)

// Group patients by their facility and count
var stats = GroupBy(cntPatients, "facility_name", [
    {name: "ClinicCount", expression: "facility_name", statistic: "COUNT"}
    ])

//  Order the results in descending order by the total counts  
var topFacilities = Top(OrderBy(Filter(stats, "facility_name &amp;lt;&amp;gt; ''"),"ClinicCount desc"), 3)

// Popup placeholder
var result = 'The Top Facilities in this area are:'

// Write the results to the popup
if(Count(topFacilities) == 0){
    return "No Patients in this area"
}

var num = 0
// Format the results for display in popup
for(var item in topFacilities){
    num++
    var num_clinics = item["ClinicCount"]
    var clinic_name = item["facility_name"]
    
    result += TextFormatting.NewLine + num + ". " + clinic_name + ": " + num_clinics + " Patients"
    
}

return result&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 13:51:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060406#M5875</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-05-21T13:51:05Z</dc:date>
    </item>
    <item>
      <title>Re: How to Use Arcade GroupBy with Top and OrderBy Expressions</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060554#M5876</link>
      <description>&lt;P&gt;Thank you Ken, yes that is an error the topClinics should be using the topFacilities field&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 18:45:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060554#M5876</guid>
      <dc:creator>izk_1989</dc:creator>
      <dc:date>2021-05-21T18:45:19Z</dc:date>
    </item>
    <item>
      <title>Re: How to Use Arcade GroupBy with Top and OrderBy Expressions</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060564#M5877</link>
      <description>&lt;P&gt;Thanks Xander, this solution works!&lt;/P&gt;</description>
      <pubDate>Fri, 21 May 2021 19:06:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1060564#M5877</guid>
      <dc:creator>izk_1989</dc:creator>
      <dc:date>2021-05-21T19:06:31Z</dc:date>
    </item>
    <item>
      <title>Re: How to Use Arcade GroupBy with Top and OrderBy Expressions</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1192475#M6297</link>
      <description>&lt;P&gt;Is there a way to format the result variable text to show "&lt;U&gt;The Top Facilites in this area are&lt;/U&gt;:" with an underline?&amp;nbsp; Or can you format the entire result with HTML somehow?&lt;/P&gt;</description>
      <pubDate>Fri, 15 Jul 2022 14:05:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1192475#M6297</guid>
      <dc:creator>MGT8C2U</dc:creator>
      <dc:date>2022-07-15T14:05:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to Use Arcade GroupBy with Top and OrderBy Expressions</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1223508#M6377</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I found this thread while searching for help with using Orderby, however, I'm very new to Arcade and I am not sure where to insert the function. Here is my code that I created already.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;var intersectLayer =Intersects(FeatureSetByName($map, "CAMS Address Points"), $feature)
var feature = FeatureSetByName($map, "CAMS Address Points")
var results = ""
for (var f in intersectLayer){
if (results ==""){
results = f.Number;
} else{
results += ", " + f.Number + iif(f.NumSuffix == '&amp;lt;Null&amp;gt;', ' ', f.NumSuffix);
}
}
return results&lt;/LI-CODE&gt;&lt;P&gt;Basically, I have a parcel and I am trying to list the address points within that parcel.&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 20:54:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1223508#M6377</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-10-19T20:54:01Z</dc:date>
    </item>
    <item>
      <title>Re: How to Use Arcade GroupBy with Top and OrderBy Expressions</title>
      <link>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1269623#M6532</link>
      <description>&lt;P&gt;Hi Xander.&lt;/P&gt;&lt;P&gt;Is there any way to do this same type of thing with line features? I have a feature layer that is "Paint Lines 2017". This layer contains 2 fields "PAINT_WID' and 'PAINT_COL'. I have been trying to modify your code above to fit a solution for what I need. I need to know the quantity of paint lines inside of a polygon based on their size ('PAINT_WID') and their color ('PAINT_COL') and I am trying to return the quantities of each&amp;nbsp; type in a popup in Arcgis Online. I attached a snip of what I am trying to achieve. I appreciate your help!&lt;/P&gt;</description>
      <pubDate>Mon, 20 Mar 2023 20:18:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/how-to-use-arcade-groupby-with-top-and-orderby/m-p/1269623#M6532</guid>
      <dc:creator>VeronicaS</dc:creator>
      <dc:date>2023-03-20T20:18:21Z</dc:date>
    </item>
  </channel>
</rss>

