<?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: Include sum and average in bar chart using data expression/arcade in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/include-sum-and-average-in-bar-chart-using-data/m-p/1393420#M9256</link>
    <description>&lt;P&gt;&lt;EM&gt;Are you wanting the "goal" value to come from the selected feature?&amp;nbsp; - &lt;/EM&gt;yes but it isn't a deal breaker for my case. I am trying to find the average of target_goal and use that as a field in my bar chart. If I do group by would it look something like this? Perhaps I am doing this all wrong.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com/"),
  "384158f2ebe34f8ba8b0b39dfe5f5af5",
  0,
  [
    'Jurisdiction', 
    'core_capability', 
    'target',
    'target_goal',
    'target_value_final'],
  false
);

var goal_group = GroupBy(fs, 'target_goal', {name: 'Goal', statistic: 'Count'})

var value_group = GroupBy(fs, 'target_value_final', {name: 'Goal', statistic: 'Sum'})

var end_value = value_group / goal_group

return end_value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 08 Mar 2024 20:42:48 GMT</pubDate>
    <dc:creator>dwold</dc:creator>
    <dc:date>2024-03-08T20:42:48Z</dc:date>
    <item>
      <title>Include sum and average in bar chart using data expression/arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/include-sum-and-average-in-bar-chart-using-data/m-p/1393130#M9247</link>
      <description>&lt;P&gt;I am trying to write a data expression that finds the count of that field. Then calculates the average of a field (filter/selection dependent) and use that in a bar chart along with the sum of another field.&lt;/P&gt;&lt;P&gt;In the picture below, I am trying to get the Target Goal to be 12 (24/2 records) while the Target Value (14) is the sum of 2 values.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dwold_1-1709908832444.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/97359i159933F10FE0AC1D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="dwold_1-1709908832444.png" alt="dwold_1-1709908832444.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com/"),
  "384158f2ebe34f8ba8b0b39dfe5f5af5",
  0,
  [
    'Jurisdiction', 
    'core_capability', 
    'target',
    'target_goal',
    'target_value_final'],
  false
);

var tar_goal = $feature.target_goal

var tar_final = Filter(fs, "target_goal = @tar_goal")

//find the total count of tar_final
var tar_count =  Count(tar_final)

//find sum of target_goal
var goal_sum = Sum($feature, tar_goal)

//Divide the sum of target_goal by target goal count
var targets = goal_sum/tar_count

return targets&lt;/LI-CODE&gt;&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/294341"&gt;@JohannesLindner&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 14:44:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/include-sum-and-average-in-bar-chart-using-data/m-p/1393130#M9247</guid>
      <dc:creator>dwold</dc:creator>
      <dc:date>2024-03-08T14:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: Include sum and average in bar chart using data expression/arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/include-sum-and-average-in-bar-chart-using-data/m-p/1393195#M9249</link>
      <description>&lt;P&gt;Remember, you need to return a FeatureSet from a Data Expression. Also, in a Data Expression, there is no global &lt;STRONG&gt;$feature&lt;/STRONG&gt;.&lt;/P&gt;&lt;P&gt;You can get the count and sum both out of a GroupBy function, and even do some derived values involving multiple fields.&lt;/P&gt;&lt;P&gt;The tricky part is "filter/selection dependent". Aggregating in a Data Expression is going to break any kind of per-feature identification in the data.&lt;/P&gt;&lt;P&gt;Are you wanting the "goal" value to come from the selected feature? I don't believe there's a way to pipe values into a data expression from the dashboard's interactivity.&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 15:47:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/include-sum-and-average-in-bar-chart-using-data/m-p/1393195#M9249</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2024-03-08T15:47:18Z</dc:date>
    </item>
    <item>
      <title>Re: Include sum and average in bar chart using data expression/arcade</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/include-sum-and-average-in-bar-chart-using-data/m-p/1393420#M9256</link>
      <description>&lt;P&gt;&lt;EM&gt;Are you wanting the "goal" value to come from the selected feature?&amp;nbsp; - &lt;/EM&gt;yes but it isn't a deal breaker for my case. I am trying to find the average of target_goal and use that as a field in my bar chart. If I do group by would it look something like this? Perhaps I am doing this all wrong.&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fs = FeatureSetByPortalItem(
  Portal("https://www.arcgis.com/"),
  "384158f2ebe34f8ba8b0b39dfe5f5af5",
  0,
  [
    'Jurisdiction', 
    'core_capability', 
    'target',
    'target_goal',
    'target_value_final'],
  false
);

var goal_group = GroupBy(fs, 'target_goal', {name: 'Goal', statistic: 'Count'})

var value_group = GroupBy(fs, 'target_value_final', {name: 'Goal', statistic: 'Sum'})

var end_value = value_group / goal_group

return end_value&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Mar 2024 20:42:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/include-sum-and-average-in-bar-chart-using-data/m-p/1393420#M9256</guid>
      <dc:creator>dwold</dc:creator>
      <dc:date>2024-03-08T20:42:48Z</dc:date>
    </item>
  </channel>
</rss>

