<?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 ArcGIS Dashboard Arcade Group and Join Table in ArcGIS Dashboards Questions</title>
    <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196821#M6618</link>
    <description>&lt;P&gt;Hello! I have a table in AGOL. I want to group it in two different ways and then join those 2 tables together to calculate a percent for a dashboard. When I test it, I keep getting the general "&lt;SPAN class=""&gt;Execution Error:&lt;/SPAN&gt;&lt;SPAN&gt;Error". Any idea what I'm doing wrong here?&lt;BR /&gt;&lt;/SPAN&gt;&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;// Write an expression that returns a FeatureSet.
// Documentation: https://arcg.is/3c419TD
// Samples: https://arcg.is/38SEWWz

var portal = Portal('https://phl.maps.arcgis.com');
var fs = FeatureSetByPortalItem(
    portal,
    '4de29dcdbea84087842717a6143a68fd',
    0,
    [
        'DATE_FILTER',
        'POSITION_TYPE',
        'RACE_ETHNICITY',
        'HIRING_DEPARTMENT',
        'TOTAL_COUNT'
    ],
    false
);

var race_total = GroupBy(fs, 
                    [
                        {name: 'DATE_FILTER', expression: 'DATE_FILTER' },
                        {name: 'RACE_ETHNICITY', expressions: 'RACE_ETHNICITY'}
                    ],
                    [{
                        name:'TOTAL_RACE',
                        expression:'TOTAL_COUNT',
                        statistic:'SUM'}]
);

var total = GroupBy(fs, 
                    ['DATE_FILTER'],
                    [{
                        name:'TOTAL_EMP',
                        expression:'TOTAL_COUNT',
                        statistic:'SUM'}]
);

// Create empty features array and feat object
var features = [];
var feat;

// Populate Feature Array
for (var r in race_total) {
    var tableID = r["DATE_FILTER"]
    for (var t in Filter(total, "DATE_FILTER = "+tableID)){
        feat = {
            attributes: {
                DATE_FILTER: tableID,
                RACE_ETHNICITY: r["RACE_ETHNICITY"],
				TOTAL_RACE: r["TOTAL_RACE"],
                TOTAL_EMP: t["TOTAL_EMP"],
                PER_RACE: Round((r["TOTAL_RACE"])/(t["TOTAL_EMP"])*100,2),
            }
        }
    
    Push(features, feat)
    }
}

var joinedDict = {
    fields: [
        { name: "DATE_FILTER", type: "esriFieldTypeString" },
        { name: "RACE_ETHNICITY", type: "esriFieldTypeString" },	
        { name: "TOTAL_RACE", type: "esriFieldTypeDouble" },
        { name: "TOTAL_EMP", type: "esriFieldTypeDouble" },
        { name: "PER_RACE", type: "esriFieldTypeDouble" },
    ],
    'geometryType': '',
    'features':features
};
    
// Return dictionary cast as a feature set 
return FeatureSet(Text(joinedDict));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 28 Jul 2022 15:36:43 GMT</pubDate>
    <dc:creator>Anonymous User</dc:creator>
    <dc:date>2022-07-28T15:36:43Z</dc:date>
    <item>
      <title>ArcGIS Dashboard Arcade Group and Join Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196821#M6618</link>
      <description>&lt;P&gt;Hello! I have a table in AGOL. I want to group it in two different ways and then join those 2 tables together to calculate a percent for a dashboard. When I test it, I keep getting the general "&lt;SPAN class=""&gt;Execution Error:&lt;/SPAN&gt;&lt;SPAN&gt;Error". Any idea what I'm doing wrong here?&lt;BR /&gt;&lt;/SPAN&gt;&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;// Write an expression that returns a FeatureSet.
// Documentation: https://arcg.is/3c419TD
// Samples: https://arcg.is/38SEWWz

var portal = Portal('https://phl.maps.arcgis.com');
var fs = FeatureSetByPortalItem(
    portal,
    '4de29dcdbea84087842717a6143a68fd',
    0,
    [
        'DATE_FILTER',
        'POSITION_TYPE',
        'RACE_ETHNICITY',
        'HIRING_DEPARTMENT',
        'TOTAL_COUNT'
    ],
    false
);

var race_total = GroupBy(fs, 
                    [
                        {name: 'DATE_FILTER', expression: 'DATE_FILTER' },
                        {name: 'RACE_ETHNICITY', expressions: 'RACE_ETHNICITY'}
                    ],
                    [{
                        name:'TOTAL_RACE',
                        expression:'TOTAL_COUNT',
                        statistic:'SUM'}]
);

var total = GroupBy(fs, 
                    ['DATE_FILTER'],
                    [{
                        name:'TOTAL_EMP',
                        expression:'TOTAL_COUNT',
                        statistic:'SUM'}]
);

// Create empty features array and feat object
var features = [];
var feat;

// Populate Feature Array
for (var r in race_total) {
    var tableID = r["DATE_FILTER"]
    for (var t in Filter(total, "DATE_FILTER = "+tableID)){
        feat = {
            attributes: {
                DATE_FILTER: tableID,
                RACE_ETHNICITY: r["RACE_ETHNICITY"],
				TOTAL_RACE: r["TOTAL_RACE"],
                TOTAL_EMP: t["TOTAL_EMP"],
                PER_RACE: Round((r["TOTAL_RACE"])/(t["TOTAL_EMP"])*100,2),
            }
        }
    
    Push(features, feat)
    }
}

var joinedDict = {
    fields: [
        { name: "DATE_FILTER", type: "esriFieldTypeString" },
        { name: "RACE_ETHNICITY", type: "esriFieldTypeString" },	
        { name: "TOTAL_RACE", type: "esriFieldTypeDouble" },
        { name: "TOTAL_EMP", type: "esriFieldTypeDouble" },
        { name: "PER_RACE", type: "esriFieldTypeDouble" },
    ],
    'geometryType': '',
    'features':features
};
    
// Return dictionary cast as a feature set 
return FeatureSet(Text(joinedDict));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:36:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196821#M6618</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-07-28T15:36:43Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard Arcade Group and Join Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196845#M6619</link>
      <description>&lt;P&gt;I think you want your &lt;STRONG&gt;Push &lt;/STRONG&gt;statement to be inside of the of &lt;STRONG&gt;for (var t...&lt;/STRONG&gt; block, not outside of it. Otherwise it's only going to push &lt;STRONG&gt;feat&lt;/STRONG&gt; into the array once for each loop of the &lt;STRONG&gt;for (var r... &lt;/STRONG&gt;block. Unless that's what you want?&lt;/P&gt;&lt;P&gt;Also, what kind of field is "DATE_FILTER"?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 15:53:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196845#M6619</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-07-28T15:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard Arcade Group and Join Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196858#M6620</link>
      <description>&lt;P&gt;Thanks Josh! I switched the&amp;nbsp;&lt;STRONG&gt;Push&lt;/STRONG&gt; statement, but that did not work (see code below). I had the&amp;nbsp;&lt;STRONG&gt;Push&lt;/STRONG&gt; in the original spot only because that is where the &lt;A href="https://github.com/Esri/arcade-expressions/blob/master/dashboard_data/JoinLayerFieldsToTable.md" target="_blank" rel="noopener"&gt;example&lt;/A&gt; had it. I received the same error.&lt;/P&gt;&lt;P&gt;DATE_FILTER is a string, formatted YYYY-MM&lt;/P&gt;&lt;P&gt;Any other ideas? I'm pretty new to Arcade so this is a struggle &lt;span class="lia-unicode-emoji" title=":confused_face:"&gt;😕&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;var portal = Portal('https://phl.maps.arcgis.com');
var fs = FeatureSetByPortalItem(
    portal,
    '4de29dcdbea84087842717a6143a68fd',
    0,
    [
        'DATE_FILTER',
        'POSITION_TYPE',
        'RACE_ETHNICITY',
        'HIRING_DEPARTMENT',
        'TOTAL_COUNT'
    ],
    false
);

var race_total = GroupBy(fs, 
                    [
                        {name: 'DATE_FILTER', expression: 'DATE_FILTER' },
                        {name: 'RACE_ETHNICITY', expressions: 'RACE_ETHNICITY'}
                    ],
                    [{
                        name:'TOTAL_RACE',
                        expression:'TOTAL_COUNT',
                        statistic:'SUM'}]
);

var total = GroupBy(fs, 
                    ['DATE_FILTER'],
                    [{
                        name:'TOTAL_EMP',
                        expression:'TOTAL_COUNT',
                        statistic:'SUM'}]
);

// Create empty features array and feat object
var features = [];
var feat;

// Populate Feature Array
for (var r in race_total) {
    var tableID = r["DATE_FILTER"]
    for (var t in Filter(total, "DATE_FILTER = "+tableID)){
        feat = {
            attributes: {
                DATE_FILTER: tableID,
                RACE_ETHNICITY: r["RACE_ETHNICITY"],
				TOTAL_RACE: r["TOTAL_RACE"],
                TOTAL_EMP: t["TOTAL_EMP"],
                //PER_RACE: Round((r["TOTAL_RACE"])/(t["TOTAL_EMP"])*100,2),
            }
        }
    }
    Push(features, feat)
}

var joinedDict = {
    fields: [
        { name: "DATE_FILTER", type: "esriFieldTypeString" },
        { name: "RACE_ETHNICITY", type: "esriFieldTypeString" },	
        { name: "TOTAL_RACE", type: "esriFieldTypeDouble" },
        { name: "TOTAL_EMP", type: "esriFieldTypeDouble" },
        //{ name: "PER_RACE", type: "esriFieldTypeDouble" },
    ],
    'geometryType': '',
    'features':features
};
    
// Return dictionary cast as a feature set 
return FeatureSet(Text(joinedDict));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 16:07:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196858#M6620</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-07-28T16:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard Arcade Group and Join Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196893#M6622</link>
      <description>&lt;P&gt;This would be a great time to test out &lt;STRONG&gt;Console &lt;/STRONG&gt;statements. By using &lt;STRONG&gt;Console('some text')&lt;/STRONG&gt;, you can print informational messages to the console, which is super helpful for identifying where a script is going wrong.&lt;/P&gt;&lt;P&gt;I added a few to your expression, and I can see that my console messages stop appearing in the first loop starting in line 40. It appears to be related to your filter statement.&lt;/P&gt;&lt;P&gt;Looking at this a bit closer, you're really just trying to pull the total out, and your filtered FeatureSet is probably a single row. In that case, you can just use &lt;STRONG&gt;First&lt;/STRONG&gt;, then access the attribute directly, and not bother with a nested for loop.&lt;/P&gt;&lt;P&gt;Also, check out the use of &lt;STRONG&gt;template literals &lt;/STRONG&gt;to pipe variables into a string without needing to use concatenation.&lt;/P&gt;&lt;P&gt;&amp;nbsp;All that aside, I think the issue here is actually the data itself. When I try to test this, I can see the server returning an error message in the console, and it lists &lt;EM&gt;this &lt;/EM&gt;as the query string:&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;" (DATE_FILTER = (2019 - 5) ) "&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Are your values formatted with spaces and parentheses like that? I could see the server interpreting that as a mathematical statement, and it's trying to filter based on the results, i.e., &lt;STRONG&gt;2014&lt;/STRONG&gt;, in the example above.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class=""&gt;Try putting single quotes around your &lt;STRONG&gt;tableID&lt;/STRONG&gt; in the expression so that the server knows it's text, not a formula. When I do that, I can see that the server is working through the featureset, sending repeated queries to the server, and the error messages go away. Seems to take a &lt;EM&gt;while &lt;/EM&gt;to run, though, but it works.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="jcarlson_0-1659026801110.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/47044i3D5DAEE8A8B5FFC4/image-size/medium?v=v2&amp;amp;px=400" role="button" title="jcarlson_0-1659026801110.png" alt="jcarlson_0-1659026801110.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;To wrap this up, use this line the replace your line 42, then remove the closing curly bracket on line 52 that used to define the &lt;STRONG&gt;for (var t...&lt;/STRONG&gt; loop. Lines 43 - 51 can remain as there are.&lt;/P&gt;&lt;PRE&gt;var t = First(Filter(total, `DATE_FILTER = '${tableID}'`))&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 16:50:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196893#M6622</guid>
      <dc:creator>jcarlson</dc:creator>
      <dc:date>2022-07-28T16:50:06Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard Arcade Group and Join Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196941#M6624</link>
      <description>&lt;P&gt;Thanks so much! That last line did the trick.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jul 2022 18:07:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1196941#M6624</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-07-28T18:07:44Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Dashboard Arcade Group and Join Table</title>
      <link>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1211249#M6792</link>
      <description>&lt;P&gt;Hello!,&lt;/P&gt;&lt;P&gt;I have a very similar data expression using the same join example that 'almost' works except I cannot get the max_samptime attribute to populate in the result Feature Dataset although I believe the other data is accurate. At the moment I have it commented out in the code included and have tried several renditions, but I just can not figure it out.&amp;nbsp; I would so appreciate your thoughts! Thanks, Kathy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;var fs = FeatureSetByPortalItem(Portal('https://www.arcgis.com'), '669d6d77f2bc4ca7ad1ec208c3db90fd', 1, ["fishdataid","towername",'samptime','stockgroup'], false);

//return fs
var grouped = GroupBy(fs, ['fishdataid'], [
    { name: 'max_samptime', expression: "samptime", statistic: 'MAX' }]);
//return grouped


var features = [];
var feat;


for (var f in grouped){
    var fish = f["fishdataid"]
    var sdate = ToUTC(f["max_samptime"])
    var sql = "samptime = '" + sdate + "'AND fishdataid = '" + fish + "'"
    for (var p in Filter(fs, sql)){
        feat = {
            attributes: {
                fishdataid: fish,
                //max_samptime: sdate,
                towername: p['towername'],
                stockgroup: p['stockgroup'],
            }
        }
    
    Push(features,feat)
    }
}

var joinedDict = {
    fields: [
        {name: "fishdataid", type: "esriFieldTypeInteger"},
        {name: "max_samptime", type: "esriFieldTypeDate"},
        {name: "towername", type: "esriFieldTypeString"},
        {name: "stockgroup", type: "esriFieldTypeString"},   
    ],
    'geometryType': '',
    'features': features
};

return FeatureSet(Text(joinedDict));&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 09 Sep 2022 19:21:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-dashboards-questions/arcgis-dashboard-arcade-group-and-join-table/m-p/1211249#M6792</guid>
      <dc:creator>kmsmikrud</dc:creator>
      <dc:date>2022-09-09T19:21:34Z</dc:date>
    </item>
  </channel>
</rss>

