<?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: Dashboard Data Expression for Average in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-for-average/m-p/1180178#M6389</link>
    <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-dashboards-blog/joining-two-feature-sets-together-and-getting-a/ba-p/1123500" target="_blank"&gt;Joining two Feature Sets together and getting a co... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;May be this post might help you.&lt;/P&gt;&lt;P&gt;I was able to pull the results I wanted for my dashboard by running a loop and a inner loop&lt;/P&gt;</description>
    <pubDate>Mon, 06 Jun 2022 12:40:47 GMT</pubDate>
    <dc:creator>kdoshiwork</dc:creator>
    <dc:date>2022-06-06T12:40:47Z</dc:date>
    <item>
      <title>Dashboard Data Expression for Average</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-for-average/m-p/1180158#M6388</link>
      <description>&lt;P&gt;Hello - I am using Dashboard to present some metrics from a map. The data set features buildings with data such as the campus they're in, the electric usage and floor area. One of the metrics I want to display is aggregated average electricity use at campus area (i.e. sum up the total electrical usage over features within a campus and divide by the area footprint of buildings in the same campus). I've been trying to use data expressions to do this but have been struggling as I haven't used Arcade much, was hoping someone could help.&lt;/P&gt;&lt;P&gt;So far I've used the GroupBy (see below) to see a table of aggregated values by campus, but I'm not sure how to then add a field and caluclate the use by square meter.&lt;/P&gt;&lt;P&gt;Don't think this is the best method regardless as ideally the filter on the dashboard will select the campus and the expression will just return (sum of all selected electricity use) / (sum of selected area).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;var portal = Portal('https://www.arcgis.com');
var fs = FeatureSetByPortalItem(
    portal,
    '14635dbc307947efa58a1b363feb43a5');

var CampusAgg = GroupBy(fs,['Campus_1'],[
    {name:'Campus_Floor_Area', expression:'Floor_Area', statistic: 'SUM'},
    {name:'Campus_Electricity_kWh', expression:'Electricity_kWh', statistic: 'SUM'},
    ]);

return CampusAgg;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 11:20:07 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-for-average/m-p/1180158#M6388</guid>
      <dc:creator>KatieSelfEd</dc:creator>
      <dc:date>2022-06-06T11:20:07Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression for Average</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-for-average/m-p/1180178#M6389</link>
      <description>&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-dashboards-blog/joining-two-feature-sets-together-and-getting-a/ba-p/1123500" target="_blank"&gt;Joining two Feature Sets together and getting a co... - Esri Community&lt;/A&gt;&lt;/P&gt;&lt;P&gt;May be this post might help you.&lt;/P&gt;&lt;P&gt;I was able to pull the results I wanted for my dashboard by running a loop and a inner loop&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 12:40:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-for-average/m-p/1180178#M6389</guid>
      <dc:creator>kdoshiwork</dc:creator>
      <dc:date>2022-06-06T12:40:47Z</dc:date>
    </item>
    <item>
      <title>Re: Dashboard Data Expression for Average</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-for-average/m-p/1180182#M6390</link>
      <description>&lt;P&gt;I would agree that it's probably not the best approach, if you want the values to be filtered later on. Keep in mind that an&amp;nbsp;&lt;STRONG&gt;Indicator&amp;nbsp;&lt;/STRONG&gt;or&amp;nbsp;&lt;STRONG&gt;Chart&lt;/STRONG&gt; widget can handle the aggregation for you. But you'll still need to get the electrical usage per square foot as its own "field", since (average(a) / average(b)) is not the same as average(a/b).&lt;/P&gt;&lt;P&gt;There are two ways to do this. The pure data expression way would be to loop over your input featureset and calculate that new field.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var out_dict = {
    fields: [
        {name: 'Floor_Area', type: 'esriFieldTypeDouble'},
        {name: 'Electricity_kWh', type: 'esriFieldTypeInteger'},
        {name: 'usage_per_sqft', type: 'esriFieldTypeDouble'},
        {name: 'Campus', type: 'esriFieldTypeString'}
        // plus whatever other fields you need in the output
    ],
    geometryType: '',
    features: []
}

for (var f in fs){
    Push(
        out_dict[features],
        {
            attributes: {
                Floor_Area: f['Floor_Area'],
                Electricity_kWh: f['Electricity_kWh'],
                Campus: f['Campus'],
                usage_per_sqft: f['Electricity_kWh'] / f['Floor_Area']
            }
        }
    )
}

return FeatureSet(Text(out_dict))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An easier way, however, is to use GroupBy, but in a slightly different way. Creating a new field is a bit easier at times using SQL in GroupBy, and by "grouping" by a unique field, we get the same features as the input, but with our added information. Since each unique ID only has a single feature, taking the "sum" gives us our input values back unchanged.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var CampusAgg = GroupBy(
    fs,
    ['objectID', 'Floor_Area', 'Electricity_kWh'], // put in all the fields you want to retain in the output
    {name: 'usage_per_sqft', expression: 'Electricity_kWh / Floor_Area', statistic: 'SUM'}
)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 06 Jun 2022 13:02:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/dashboard-data-expression-for-average/m-p/1180182#M6390</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-06-06T13:02:41Z</dc:date>
    </item>
  </channel>
</rss>

