<?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 Create chart to tally same value across multiple fields in the same feature layer in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-chart-to-tally-same-value-across-multiple/m-p/1107322#M5239</link>
    <description>&lt;P&gt;I'm really trying to display a line chart in our Arcgis Dashboard that utilizes an expression counting the same value from multiple fields.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Submitter    Choice 1    Choice 2    Choice 3
John            1            5           6
Amy             5            2           8
Alex            6            4           5&lt;/LI-CODE&gt;&lt;P&gt;So, Ideally I would like visualize 5 has the highest count currently as users submit their surveys.&lt;/P&gt;&lt;P&gt;I was trying to refer to the samples (&lt;A href="https://arcg.is/38SEWWz" target="_blank"&gt;https://arcg.is/38SEWWz&lt;/A&gt;), but I'm still left a little stumped).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Struggling for ideas&lt;/P&gt;</description>
    <pubDate>Wed, 13 Oct 2021 21:40:01 GMT</pubDate>
    <dc:creator>NikeshPatel</dc:creator>
    <dc:date>2021-10-13T21:40:01Z</dc:date>
    <item>
      <title>Create chart to tally same value across multiple fields in the same feature layer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-chart-to-tally-same-value-across-multiple/m-p/1107322#M5239</link>
      <description>&lt;P&gt;I'm really trying to display a line chart in our Arcgis Dashboard that utilizes an expression counting the same value from multiple fields.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;Submitter    Choice 1    Choice 2    Choice 3
John            1            5           6
Amy             5            2           8
Alex            6            4           5&lt;/LI-CODE&gt;&lt;P&gt;So, Ideally I would like visualize 5 has the highest count currently as users submit their surveys.&lt;/P&gt;&lt;P&gt;I was trying to refer to the samples (&lt;A href="https://arcg.is/38SEWWz" target="_blank"&gt;https://arcg.is/38SEWWz&lt;/A&gt;), but I'm still left a little stumped).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Struggling for ideas&lt;/P&gt;</description>
      <pubDate>Wed, 13 Oct 2021 21:40:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-chart-to-tally-same-value-across-multiple/m-p/1107322#M5239</guid>
      <dc:creator>NikeshPatel</dc:creator>
      <dc:date>2021-10-13T21:40:01Z</dc:date>
    </item>
    <item>
      <title>Re: Create chart to tally same value across multiple fields in the same feature layer</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-chart-to-tally-same-value-across-multiple/m-p/1107555#M5242</link>
      <description>&lt;P&gt;Can you share the code you've got so far? If you've already found the Data Expression samples, plugging your data into the right one is not terribly difficult. But yours &lt;EM&gt;is &lt;/EM&gt;a bit different from the samples.&lt;/P&gt;&lt;P&gt;It's hard to say without having access to the data, but I think you'll probably want to:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Use GroupBy three times, once for each choice field&lt;OL&gt;&lt;LI&gt;Group by the value in the choice field, returning the &lt;EM&gt;count&lt;/EM&gt; of features in the group as well&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;LI&gt;Create a list of dicts, each with a "choice value" and "count"&lt;/LI&gt;&lt;LI&gt;Iterate over each grouped featureset and add the counts to the appropriate item in your list.&lt;/LI&gt;&lt;LI&gt;Create a FeatureSet using the list of dicts.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Any chance the layer is public? It'd be more helpful to be able to test this against the same data.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var fs = FeatureSetByPortalItem(Portal('your-portal-url'), 'itemid', layerIndex, ["choice1", "choice2", "choice3"], false)

var choices = {
    "1": 0,
    "2": 0,
    // And so on, until there is an item for every possible choice.
}

// Group by choices and get counts
var g1 = GroupBy(fs, {name: 'choice', expression: 'choice1'}, {name: 'c_count', expression: '1', statistic: 'COUNT'})
var g2 = GroupBy(fs, {name: 'choice', expression: 'choice2'}, {name: 'c_count', expression: '1', statistic: 'COUNT'})
var g3 = GroupBy(fs, {name: 'choice', expression: 'choice3'}, {name: 'c_count', expression: '1', statistic: 'COUNT'})

// Iterate over grouped FeatureSets, populate dict
for(var g in g1){
    choices[g["choice"]] += g["c_count"]
}

for(var g in g12){
    choices[g["choice"]] += g["c_count"]
}

for(var g in g3){
    choices[g["choice"]] += g["c_count"]
}

// Create array of features from dict
var feats = []

// Populate feature array from dict
for(var c in choices){
    var feat = {"attributes": {"choice": c}, {"c_count": choices[c]}}
    Push(feats, feat)

// Create FeatureSet from JSON, using array of features
          
var outDict= { 
    'fields': [{'name':'choice', 'type':'esriFieldTypeString'},
               {'name':'c_count', 'type':'esriFieldTypeInteger'}], 
    'geometryType': '', 
    'features': feats
    }; 

return FeatureSet(Text(outDict)); &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;You could probably refine that code with a custom function, too, but that could be a decent starting point for you.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Oct 2021 15:28:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-chart-to-tally-same-value-across-multiple/m-p/1107555#M5242</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2021-10-14T15:28:00Z</dc:date>
    </item>
  </channel>
</rss>

