<?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: Using SQL in an Arcade GroupBy expression in ArcGIS Online Questions</title>
    <link>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540311#M61570</link>
    <description>&lt;P&gt;In &lt;STRONG&gt;GroupBy&lt;/STRONG&gt;, the "expression" key is specifically looking for valid SQL.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/198908"&gt;@JasonBatory&lt;/a&gt;in your series of expressions, you're treating the "expression" like it's a filter. In GroupBy, it's going to attempt to return the statistic from the expression, and you can't really count whether or not the floorcount is equal to a value.&lt;/P&gt;&lt;P&gt;To use &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/712076"&gt;@CodyPatterson&lt;/a&gt; 's idea, but in SQL, you can use CASE:&lt;/P&gt;&lt;P&gt;"CASE WHEN FLOORCOUNT = 0 THEN 1 ELSE 0 END"&lt;/P&gt;&lt;P&gt;Use that with the statistic "SUM", and you'll get the number of records with that particular floor count value.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1726751184694.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115428i536A05D5DFE5959E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1726751184694.png" alt="jcarlson_0-1726751184694.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 19 Sep 2024 13:07:15 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2024-09-19T13:07:15Z</dc:date>
    <item>
      <title>Using SQL in an Arcade GroupBy expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540263#M61567</link>
      <description>&lt;P&gt;Can anyone confirm whether expressions like this should work, or if my syntax is just wrong?&lt;/P&gt;&lt;P&gt;In my Arcade groupBy function I want to use SQL in the expression, like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com"),
  "6200db0b80de4341ae8ee2b62d606e67",
  0, 
  ["*"], 
  false 
);

//For each building FeatureCode
//Count how many buildings with each FloorCount
return GroupBy(fs, 'FEATURECODE', 
[{name: 'Floors_0', expression: 'FLOORCOUNT = 0', statistic: 'Count'},
{name: 'Floors_1', expression: 'FLOORCOUNT = 1', statistic: 'Count'},
{name: 'Floors_2', expression: 'FLOORCOUNT = 2', statistic: 'Count'},])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;This returns an error:&lt;/P&gt;&lt;PRE&gt;&lt;SPAN&gt;Test execution error: Unknown Error. Verify test data.&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I've tried various different syntax for the 'FLOORCOUNT = 0' statement with the same results.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 08:25:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540263#M61567</guid>
      <dc:creator>JasonBatory</dc:creator>
      <dc:date>2024-09-19T08:25:59Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL in an Arcade GroupBy expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540295#M61569</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/198908"&gt;@JasonBatory&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could you give this here a shot? You may want to use Iif in terms of the expression:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com"),
  "6200db0b80de4341ae8ee2b62d606e67",
  0, 
  ["*"], 
  false 
);

return GroupBy(fs, 'FEATURECODE', 
[{name: 'Floors_0', expression: IIf($feature.FLOORCOUNT == 0, 1, 0), statistic: 'Sum'},
{name: 'Floors_1', expression: IIf($feature.FLOORCOUNT == 1, 1, 0), statistic: 'Sum'},
{name: 'Floors_2', expression: IIf($feature.FLOORCOUNT == 2, 1, 0), statistic: 'Sum'}])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;The 0, 1, 0 in the first one, is the values of the condition, true value, and false value, so if it is 0 it will return true, otherwise false.&lt;/P&gt;&lt;P&gt;Let me know if this helps out!&lt;/P&gt;&lt;P&gt;Cody&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 11:11:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540295#M61569</guid>
      <dc:creator>CodyPatterson</dc:creator>
      <dc:date>2024-09-19T11:11:29Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL in an Arcade GroupBy expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540311#M61570</link>
      <description>&lt;P&gt;In &lt;STRONG&gt;GroupBy&lt;/STRONG&gt;, the "expression" key is specifically looking for valid SQL.&lt;/P&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/198908"&gt;@JasonBatory&lt;/a&gt;in your series of expressions, you're treating the "expression" like it's a filter. In GroupBy, it's going to attempt to return the statistic from the expression, and you can't really count whether or not the floorcount is equal to a value.&lt;/P&gt;&lt;P&gt;To use &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/712076"&gt;@CodyPatterson&lt;/a&gt; 's idea, but in SQL, you can use CASE:&lt;/P&gt;&lt;P&gt;"CASE WHEN FLOORCOUNT = 0 THEN 1 ELSE 0 END"&lt;/P&gt;&lt;P&gt;Use that with the statistic "SUM", and you'll get the number of records with that particular floor count value.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1726751184694.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115428i536A05D5DFE5959E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1726751184694.png" alt="jcarlson_0-1726751184694.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 13:07:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540311#M61570</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-09-19T13:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL in an Arcade GroupBy expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540384#M61573</link>
      <description>&lt;P&gt;Ok, this makes sense now. I also tried "WHERE FLOORCOUNT = 0" with count statistic, but I see this should be treated more like a decode situation using the sum statistic.&lt;/P&gt;&lt;P&gt;Thanks for your help Josh, and Cody.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 14:22:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540384#M61573</guid>
      <dc:creator>JasonBatory</dc:creator>
      <dc:date>2024-09-19T14:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL in an Arcade GroupBy expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540390#M61574</link>
      <description>&lt;P&gt;Follow up question, is there any way to add a "total" row at the bottom displaying the total of each of the columns "Floors_0", "Floors_1", etc?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 14:33:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540390#M61574</guid>
      <dc:creator>JasonBatory</dc:creator>
      <dc:date>2024-09-19T14:33:34Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL in an Arcade GroupBy expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540396#M61575</link>
      <description>&lt;P&gt;Not really. The number of rows in the output are based on the unique values in your second parameter, 'FLOORCOUNT'. There's probably some way to do a second GroupBy and merge it with the first, but it's probably not worth the trouble.&lt;/P&gt;&lt;P&gt;If you're bringing this into a Dashboard, there are lots of widgets you could use to display the totals of each of those columns. Is there a reason you want the total as a separate row in the table itself?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 14:45:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540396#M61575</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-09-19T14:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Using SQL in an Arcade GroupBy expression</title>
      <link>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540404#M61576</link>
      <description>&lt;P&gt;Yeah this is in a Dashboard, I was basically hoping to just emulate a pivot table, not a big deal.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I guess I can just rethink the design and present those totals in another way.&lt;/P&gt;&lt;P&gt;Thanks again.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Sep 2024 14:55:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-online-questions/using-sql-in-an-arcade-groupby-expression/m-p/1540404#M61576</guid>
      <dc:creator>JasonBatory</dc:creator>
      <dc:date>2024-09-19T14:55:23Z</dc:date>
    </item>
  </channel>
</rss>

