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 "Execution Error:Error". Any idea what I'm doing wrong here?
// 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));