<?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: Arcade Expression for Dashboard - GroupBy and Calculate Mean in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-for-dashboard-groupby-and/m-p/1130322#M5603</link>
    <description>&lt;P&gt;It really depends on how you need to use the output. Is this for some report, or a dashboard?&lt;/P&gt;&lt;P&gt;The built-in GroupBy function should be able to give you what you need.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var group_exp = {
    name: 'N_Mean',
    expression: '(N1 + N2 + N3) / 3',
    statistic: 'SUM'
}

return GroupBy(
    fs_filt,
    ['Date1', 'City'],
    group_exp
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One issue with the sample output table you've posted is that there is a new column for each date. While that is possible, it's not as nice to work with, and if you have many dates, can quickly become a rather unwieldy table.&lt;/P&gt;&lt;P&gt;Keeping the output of GroupBy will give you a row for each city/date combination, which can easily be visualized or further modified by other tools.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Jan 2022 15:13:45 GMT</pubDate>
    <dc:creator>jcarlson</dc:creator>
    <dc:date>2022-01-04T15:13:45Z</dc:date>
    <item>
      <title>Arcade Expression for Dashboard - GroupBy and Calculate Mean</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-for-dashboard-groupby-and/m-p/1130266#M5600</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000080"&gt;Hello everyone!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000080"&gt;I am trying to summarize a table with data, and I am not sure how to proceed.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000080"&gt;I have little programming skills &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000080"&gt;I have to go from this:&lt;/FONT&gt;&lt;/P&gt;&lt;TABLE border="0" width="480" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;Date&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;&lt;STRONG&gt;City&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;&lt;STRONG&gt;N1&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;&lt;STRONG&gt;N2&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;&lt;STRONG&gt;N3&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;06.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;Munich&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;5&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;11&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;06.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;Berlin&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;3&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;2&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;06.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;Hamburg&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;3&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;3&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;14.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;Munich&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;7&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;1&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;14.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;Berlin&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;6&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;2&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;14.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;Hamburg&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;5&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;11&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;8&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;22.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;Munich&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;1&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;2&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;22.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;Berlin&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;1&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;4&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD width="95.975px" height="15px"&gt;&lt;STRONG&gt;22.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="95.9125px" height="15px"&gt;Hamburg&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;2&lt;/TD&gt;&lt;TD width="95.7px" height="15px"&gt;2&lt;/TD&gt;&lt;TD width="95.7125px" height="15px"&gt;7&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3" color="#000080"&gt;To a table where for every city&amp;nbsp;AND for every day,&amp;nbsp;the arithmetical mean between N1, N2 and N3 values is calculated. For example, for the City of Munich on the 06/12/2021 the mean of N1, N2 and N3 is 7 (=5+5+11).&lt;/FONT&gt;&lt;/P&gt;&lt;TABLE border="0" width="384" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD width="96" height="20"&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD width="96"&gt;&lt;STRONG&gt;06.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="96"&gt;&lt;STRONG&gt;14.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD width="96"&gt;&lt;STRONG&gt;22.12.2021&lt;/STRONG&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;&lt;STRONG&gt;Munich&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;&lt;STRONG&gt;&lt;FONT color="#FF6600"&gt;7&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;3,33&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;&lt;STRONG&gt;Berlin&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;4,00&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD height="20"&gt;&lt;STRONG&gt;Hamburg&lt;/STRONG&gt;&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;3,67&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000080"&gt;I am really not sure how/when to loop and when to groupby&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000080"&gt;if anyone could help I would much appreciate it.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000080"&gt;Thanks a Lot!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" color="#000080"&gt;Dory&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;var fs = FeatureSetByPortalItem(Portal('&lt;A href="https://www.arcgis.com" target="_blank" rel="noopener"&gt;https://www.arcgis.com&lt;/A&gt;'), 'xxxxxx' , 0, ['Date1', 'City', 'N1', 'N2','N3'], false);&lt;BR /&gt;&lt;BR /&gt;var datefilter = Date(2020,12,31)&lt;BR /&gt;var fs_filt = Filter(fs, 'Datum_Meldung &amp;gt; @datefilter')&lt;/P&gt;&lt;P&gt;var fs_mean = {&lt;BR /&gt;fields: [&lt;BR /&gt;{ name: "Date1", type: "esriFieldTypeDate" },&lt;BR /&gt;{ name: "City", type: "esriFieldTypeString" },&lt;BR /&gt;{ name: "N_mean", type: "esriFieldTypeDouble" },&lt;BR /&gt;],&lt;BR /&gt;geometryType: "",&lt;BR /&gt;features: [],&lt;BR /&gt;};&lt;/P&gt;&lt;P&gt;var index = 0&lt;BR /&gt;for (var feature in fs_filt) {&lt;BR /&gt;fs_mean.features[index] = {&lt;BR /&gt;'attributes': {&lt;BR /&gt;'City' : ['City'],&lt;BR /&gt;'Datum': ['Date1'],&lt;BR /&gt;'N_mean': Sum(feature[....????)/3)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 11:58:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-for-dashboard-groupby-and/m-p/1130266#M5600</guid>
      <dc:creator>DoZ</dc:creator>
      <dc:date>2022-01-04T11:58:20Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression for Dashboard - GroupBy and Calculate Mean</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-for-dashboard-groupby-and/m-p/1130322#M5603</link>
      <description>&lt;P&gt;It really depends on how you need to use the output. Is this for some report, or a dashboard?&lt;/P&gt;&lt;P&gt;The built-in GroupBy function should be able to give you what you need.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var group_exp = {
    name: 'N_Mean',
    expression: '(N1 + N2 + N3) / 3',
    statistic: 'SUM'
}

return GroupBy(
    fs_filt,
    ['Date1', 'City'],
    group_exp
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One issue with the sample output table you've posted is that there is a new column for each date. While that is possible, it's not as nice to work with, and if you have many dates, can quickly become a rather unwieldy table.&lt;/P&gt;&lt;P&gt;Keeping the output of GroupBy will give you a row for each city/date combination, which can easily be visualized or further modified by other tools.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Jan 2022 15:13:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-for-dashboard-groupby-and/m-p/1130322#M5603</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-01-04T15:13:45Z</dc:date>
    </item>
    <item>
      <title>Re: Arcade Expression for Dashboard - GroupBy and Calculate Mean</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-for-dashboard-groupby-and/m-p/1130736#M5633</link>
      <description>&lt;P&gt;&lt;FONT color="#000080"&gt;&lt;STRONG&gt;Hello Josh,&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;&lt;STRONG&gt;thank you so much, it worked perfectly. I copy down here my finale version.&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;&lt;STRONG&gt;Not sure how you can copy&amp;amp;paste the code here and let it look like the one in your answer, but anyway:&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;var fs = FeatureSetByPortalItem(Portal('&lt;A href="https://www.arcgis.com" target="_blank" rel="noopener"&gt;https://www.arcgis.com&lt;/A&gt;'), 'xxxx' , 0, ['Date1', 'City', 'N1', 'N2','N3'], false);&lt;BR /&gt;&lt;BR /&gt;var datefilter = Date(2020,12,31)&lt;BR /&gt;var fs_filt = Filter(fs, 'Date1 &amp;gt; @datefilter')&lt;/P&gt;&lt;P&gt;var group_exp = [&lt;BR /&gt;{ name: 'N_Mean', expression: '(N1 + N2 + N3) / 3', statistic: 'SUM'}]&lt;/P&gt;&lt;P&gt;return GroupBy(fs_filt,['Date1', 'City'], group_exp)&lt;/P&gt;&lt;P&gt;return fs_filt&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#000080"&gt;The graph looks like this&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="DoZ_0-1641378272014.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/30809i4A7FBCF9889CA800/image-size/medium?v=v2&amp;amp;px=400" role="button" title="DoZ_0-1641378272014.png" alt="DoZ_0-1641378272014.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;&lt;STRONG&gt;This is exactly the result I needed! &lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;&lt;STRONG&gt;Thank you ao much,&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080"&gt;&lt;STRONG&gt;Dory&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jan 2022 10:31:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcade-expression-for-dashboard-groupby-and/m-p/1130736#M5633</guid>
      <dc:creator>DoZ</dc:creator>
      <dc:date>2022-01-05T10:31:50Z</dc:date>
    </item>
  </channel>
</rss>

