<?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 Arcade expression for ArcGIS Dashboard Pie Chart widget in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1150820#M5934</link>
    <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a beginner in all things Arcade and I'm having some trouble with an Arcade expression for ArcGIS Dashboard. I have a table of names that I will be pulling into a Pie Chart widget to show all repeated names as categories, so if John Doe is repeated 5 times and Jane Doe is repeated 3 times, then John Doe gets a bigger slice of the pie chart. But the widget has a max of 300 categories and my table has over 400 records, so I need to filter the data down to only the repeated names before it tries to render in the Pie Chart. Which leads me to trying to create a data expression.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The part I'm stuck on is figuring out what function to use to identify repeat values in a field. Online research shows quite a bit about how to find unique values, but I really need the opposite of that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal('https://someportal.com/')
var tablefs = FeatureSetByPortalItem(
    portal,
    'tableportalitemid',
    1,
    ['*'],
    false
);
// Create empty dictionary of all fields you want the pie chart to reference  
var dict = { 
  fields: [ 
    { name: "wholename", type: "esriFieldTypeString" }, 
    { name: "GlobalID", type: "esriFieldTypeGlobalID" },  
  ], 
  geometryType: "", 
  features: [], 
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the rest of the logic would be something like;&lt;/P&gt;&lt;P&gt;//Create a list of all values in tablefs wholename field&lt;/P&gt;&lt;P&gt;//Where wholenames are not distinct, store into an array.&lt;/P&gt;&lt;P&gt;//Create more logic to loop through the tablefs and if wholename value exists in array then push all matching features into dictionary&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Finally export dictionary to featureset to reference in Pie Chart Widget.&lt;/P&gt;&lt;P&gt;Thanks very much for any insight and advice,&amp;nbsp;&lt;/P&gt;&lt;P&gt;There may be a better way..&lt;/P&gt;</description>
    <pubDate>Fri, 04 Mar 2022 19:30:12 GMT</pubDate>
    <dc:creator>Caitlin_Todd_LCOR</dc:creator>
    <dc:date>2022-03-04T19:30:12Z</dc:date>
    <item>
      <title>Create Arcade expression for ArcGIS Dashboard Pie Chart widget</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1150820#M5934</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm a beginner in all things Arcade and I'm having some trouble with an Arcade expression for ArcGIS Dashboard. I have a table of names that I will be pulling into a Pie Chart widget to show all repeated names as categories, so if John Doe is repeated 5 times and Jane Doe is repeated 3 times, then John Doe gets a bigger slice of the pie chart. But the widget has a max of 300 categories and my table has over 400 records, so I need to filter the data down to only the repeated names before it tries to render in the Pie Chart. Which leads me to trying to create a data expression.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The part I'm stuck on is figuring out what function to use to identify repeat values in a field. Online research shows quite a bit about how to find unique values, but I really need the opposite of that.&amp;nbsp;&lt;/P&gt;&lt;P&gt;So far I have,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal('https://someportal.com/')
var tablefs = FeatureSetByPortalItem(
    portal,
    'tableportalitemid',
    1,
    ['*'],
    false
);
// Create empty dictionary of all fields you want the pie chart to reference  
var dict = { 
  fields: [ 
    { name: "wholename", type: "esriFieldTypeString" }, 
    { name: "GlobalID", type: "esriFieldTypeGlobalID" },  
  ], 
  geometryType: "", 
  features: [], 
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the rest of the logic would be something like;&lt;/P&gt;&lt;P&gt;//Create a list of all values in tablefs wholename field&lt;/P&gt;&lt;P&gt;//Where wholenames are not distinct, store into an array.&lt;/P&gt;&lt;P&gt;//Create more logic to loop through the tablefs and if wholename value exists in array then push all matching features into dictionary&amp;nbsp;&lt;/P&gt;&lt;P&gt;//Finally export dictionary to featureset to reference in Pie Chart Widget.&lt;/P&gt;&lt;P&gt;Thanks very much for any insight and advice,&amp;nbsp;&lt;/P&gt;&lt;P&gt;There may be a better way..&lt;/P&gt;</description>
      <pubDate>Fri, 04 Mar 2022 19:30:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1150820#M5934</guid>
      <dc:creator>Caitlin_Todd_LCOR</dc:creator>
      <dc:date>2022-03-04T19:30:12Z</dc:date>
    </item>
    <item>
      <title>Re: Create Arcade expression for ArcGIS Dashboard Pie Chart widget</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1151172#M5939</link>
      <description>&lt;P&gt;You can use the &lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#groupby" target="_blank" rel="noopener"&gt;GroupBy function&lt;/A&gt;.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// load your feature set (lines 1-8 in your code)
var dict = { 
  fields: [ 
    { name: "wholename", type: "esriFieldTypeString" }
  ], 
  geometryType: "", 
  features: [
      {"attributes": {"wholename": "John Doe"}},
      {"attributes": {"wholename": "John Doe"}},
      {"attributes": {"wholename": "John Doe"}},
      {"attributes": {"wholename": "Jane Doe"}},
      {"attributes": {"wholename": "Jane Doe"}},
      {"attributes": {"wholename": "Jane Doe"}},
      {"attributes": {"wholename": "Jane Doe"}},
      ], 
};
var fs = FeatureSet(Text(dict))

// Aggregate by wholename, use count as statistic
var aggregated_fs = GroupBy(fs, ["wholename"], {"name": "NameCount", "expression": "wholename", "statistic": "Count"})

return aggregated_fs&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1646643734701.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/35732i777B97B756B1C20B/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1646643734701.png" alt="JohannesLindner_0-1646643734701.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Mar 2022 09:03:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1151172#M5939</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-07T09:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Create Arcade expression for ArcGIS Dashboard Pie Chart widget</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1152246#M5957</link>
      <description>&lt;P&gt;Hi Johannes!&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much for your advice and the code sample, it helped me make significant progress on my Arcade expression. I'm now at the point where features are returned, but I still need to add some more logic to it.&lt;/P&gt;&lt;P&gt;Is there a way to use the 'NameCount' value in an IIF statement?&amp;nbsp;&lt;/P&gt;&lt;P&gt;so it'd look something like&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var alln = groupby(tablefs, 'wholename', {"name": "NameCount", "expression": "wholename", "statistic": "Count"});
    var dups = IIf(alln&amp;gt;1, alln,"")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Many thanks! and have a great day!&lt;/P&gt;&lt;P&gt;Caitlin&lt;/P&gt;</description>
      <pubDate>Wed, 09 Mar 2022 17:23:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1152246#M5957</guid>
      <dc:creator>Caitlin_Todd_LCOR</dc:creator>
      <dc:date>2022-03-09T17:23:03Z</dc:date>
    </item>
    <item>
      <title>Re: Create Arcade expression for ArcGIS Dashboard Pie Chart widget</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1152457#M5963</link>
      <description>&lt;P&gt;GoupBy() returns a FeatureSet (the same data type as your tablefs). If I understand your code correctly, you want to filter out names that only show up once? You can use &lt;A href="https://developers.arcgis.com/arcade/function-reference/data_functions/#filter" target="_blank" rel="noopener"&gt;Filter()&lt;/A&gt; for that:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var alln = groupby(tablefs, 'wholename', {"name": "NameCount", "expression": "wholename", "statistic": "Count"});
var dups = Filter(alln, "NameCount &amp;gt; 1")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Mar 2022 08:50:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1152457#M5963</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-10T08:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Create Arcade expression for ArcGIS Dashboard Pie Chart widget</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1152973#M5967</link>
      <description>&lt;P&gt;Thanks! Filter did the trick there.&amp;nbsp;&lt;/P&gt;&lt;P&gt;That combined with the code sample you provided earlier did the trick after configuring it to loop through all the rows in the table. But when I set it with wholename as the category it showed up with equal sized pie slices per name, as seen in the screenshots below.&lt;/P&gt;&lt;P&gt;So I think I'll be continuing to play with the script to try to compare the GroupBy featureset with the original tablefs portal item and pull out only those names that match (and pull in their GUIDS at the same time).&lt;/P&gt;&lt;P&gt;Here's what the script looks like now.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var portal = Portal('https://someportal.com/')
var tablefs = FeatureSetByPortalItem(
    portal,
    'someportalid',
    1,
    ['*'],
    false
);
// Create empty dictionary of all fields you want the pie chart to reference  
var dict = { 
  fields: [ 
    { name: "wholename", type: "esriFieldTypeString" },
    { name: "GlobalID", type: "esriFieldTypeGlobalID" },  
  ], 
  geometryType: "", 
  features: [], 
};
for (var f in tablefs) {
    var id = (['GlobalID'])
    var n = (['wholename'])
    var alln = groupby(tablefs, 'wholename', {name: "NameCount", expression: "wholename", statistic: "Count"});
    var dups = Filter(alln, "NameCount&amp;gt;1")
}
return dups&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Pie Chart with NameCount as a category&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Pie Chart showing counts of repeated names" style="width: 382px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/36148iE1A22C11B298B777/image-size/large?v=v2&amp;amp;px=999" role="button" title="dashboardpiechart.png" alt="Pie Chart showing counts of repeated names" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Pie Chart showing counts of repeated names&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;Pie Chart with wholename as a category&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="dashboardpiechartwholename.png" style="width: 276px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/36150i2B495CE686A6B83A/image-dimensions/276x303?v=v2" width="276" height="303" role="button" title="dashboardpiechartwholename.png" alt="dashboardpiechartwholename.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;I think looking for matches between Groupby function and the tablefs portal item may be outside the scope of this question?&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks again for all your help,&amp;nbsp;&lt;/P&gt;&lt;P&gt;Caitlin&lt;/P&gt;</description>
      <pubDate>Fri, 11 Mar 2022 21:06:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1152973#M5967</guid>
      <dc:creator>Caitlin_Todd_LCOR</dc:creator>
      <dc:date>2022-03-11T21:06:47Z</dc:date>
    </item>
    <item>
      <title>Re: Create Arcade expression for ArcGIS Dashboard Pie Chart widget</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1153272#M5973</link>
      <description>&lt;P&gt;So, this is a case of me not knowing how Dashboard pie charts work... I thought you would supply a numeric and a label column, in which case the GroupBy would have sufficed. But you only supply one column and ArcGIS groups those values on its own.&lt;/P&gt;&lt;P&gt;Reading your question again, you correctly outlined the general process, although you can do it without using an extra dictionary:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// load your feature set
var dict = { 
  fields: [ 
    { name: "wholename", type: "esriFieldTypeString" }
  ], 
  geometryType: "", 
  features: [
      {"attributes": {"wholename": "abc"}},
      {"attributes": {"wholename": "abc"}},
      {"attributes": {"wholename": "def"}}, // singular name
      {"attributes": {"wholename": "ghi"}},
      {"attributes": {"wholename": "ghi"}},
      {"attributes": {"wholename": "ghi"}},
      ], 
};
var tablefs = FeatureSet(Text(dict))

// group by name, only keep multiple occurences
var grouped_fs = GroupBy(tablefs, "wholename", {"name": "NameCount", "expression": "wholename", "statistic": "Count"})
var duplicate_fs = Filter(grouped_fs, "NameCount &amp;gt; 1")

// construct an SQL filter statement with which to filter the original data
// wholename IN ('Name1', 'Name2', 'Name3')
var filter_names = []
for(var f in duplicate_fs) {
    Push(filter_names, f.wholename)
}
var filter_statement = `wholename IN ('${Concatenate(filter_names, "', '")}')`

// filter the original feature set with this statement and return the result
// this contains all the original rows with duplicate names
return Filter(tablefs, filter_statement)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="JohannesLindner_0-1647242289590.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/36238iC10DF4080DB7733D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="JohannesLindner_0-1647242289590.png" alt="JohannesLindner_0-1647242289590.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 07:24:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1153272#M5973</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-03-14T07:24:55Z</dc:date>
    </item>
    <item>
      <title>Re: Create Arcade expression for ArcGIS Dashboard Pie Chart widget</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1153474#M5975</link>
      <description>&lt;P&gt;Success! Thank you so much!! the screenshot below is the breakdown of wholename and filtered to where count is greater than 1 (also grouped all counts of 2 into one category; the big gray slice).&lt;/P&gt;&lt;P&gt;Being able to retrieve the entire tablefs schema allows for a bonus functionality too. By setting layer actions between widgets off of guid fields I can replicate the functionality of a 1:M relationship class &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt; For example, select one or more pie slices to auto filter a corresponding list widget. Allow user to select multiple list items and have that filter the map widget.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm attaching the final, working code for others to reference.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;//ID portal and portal item to reference in expression
var portal = Portal('https://someportal.com/')
var tablefs = FeatureSetByPortalItem(
    portal,
    'someportalid',
    1,
    ['*'],
    false
);
//go through every row in table, groupby name and isolate where count of name is greater than 1
for (var f in tablefs) {
    var gid = (['GlobalID'])
    var n = (['wholename'])
    var alln = groupby(tablefs, 'wholename', {name: "NameCount", expression: "wholename", statistic: "Count"});
    var dups = Filter(alln, "NameCount&amp;gt;1")
//match names to only return names that are duplicated    
var filterednames = []
    for(var f in dups){
    Push(filterednames, f.wholename)
    }
}
//filter statement used to push out that match those that were duplicated
var filter_statement = `wholename IN ('${Concatenate(filterednames, "', '")}')`
//return all tablefs rows where wholename matches the names identified as duplicate
return Filter(tablefs, filter_statement)&lt;/LI-CODE&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Final pie chart showing the top repeated names with different sized pie slices" style="width: 285px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/36279i0741B366EC683711/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Caitlin_Todd_LCOR_0-1647282922471.png" alt="Final pie chart showing the top repeated names with different sized pie slices" /&gt;&lt;span class="lia-inline-image-caption" onclick="event.preventDefault();"&gt;Final pie chart showing the top repeated names with different sized pie slices&lt;/span&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Mar 2022 18:52:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/create-arcade-expression-for-arcgis-dashboard-pie/m-p/1153474#M5975</guid>
      <dc:creator>Caitlin_Todd_LCOR</dc:creator>
      <dc:date>2022-03-14T18:52:08Z</dc:date>
    </item>
  </channel>
</rss>

