Thank you very much! That put me on the right path. I was able to match my expression to your example (the GitHub link also helped) and get what I needed. I've pasted my working expression below, in case anyone in the same situation stumbles across this post.
var sql = "EXEMPT_COD IS NULL Or EXEMPT_COD = 2 Or EXEMPT_COD = 4"
var portal = Portal('https://xxxxx.xx.gov/portal');
// Create a FeatureSet for each pavement type Feature Layer.
// Group the features by the team name
var flexible = GroupBy(
Filter(FeatureSetByPortalItem(portal,'xxx',0,['Length', 'SURV_CREW', 'EXEMPT_COD'],false), sql),
['SURV_CREW'],
[{ name: 'flexible', expression: 'Length', statistic: 'SUM' }]
);
var rigid = GroupBy(
Filter(FeatureSetByPortalItem(portal,'xxx',1,['Length', 'SURV_CREW', 'EXEMPT_COD'],false), sql),
['SURV_CREW'],
[{ name: 'rigid', expression: 'Length', statistic: 'SUM' }]
);
var concrete = GroupBy(
Filter(FeatureSetByPortalItem(portal,'xxx',2,['Length', 'SURV_CREW', 'EXEMPT_COD'],false), sql),
['SURV_CREW'],
[{ name: 'concrete', expression: 'Length', statistic: 'SUM' }]
);
var gravel = GroupBy(
Filter(FeatureSetByPortalItem(portal,'xxx',3,['Length', 'SURV_CREW', 'EXEMPT_COD'],false), sql),
['SURV_CREW'],
[{ name: 'gravel', expression: 'Length', statistic: 'SUM' }]
);
// Create empty array for features, feat object to populate array
var features = [];
var feat;
// Loop through each of the four FeatureSets and populate feature array.
for (var f in flexible) {
feat = {
attributes: {
team_name: f['SURV_CREW'],
length_by_team: f['flexible'],
},
};
Push(features, feat);
}
for (var r in rigid) {
feat = {
attributes: {
team_name: r['SURV_CREW'],
length_by_team: r['rigid'],
},
};
Push(features, feat);
}
for (var c in concrete) {
feat = {
attributes: {
team_name: c['SURV_CREW'],
length_by_team: c['concrete'],
},
};
Push(features, feat);
}
for (var g in gravel) {
feat = {
attributes: {
team_name: g['SURV_CREW'],
length_by_team: g['gravel'],
},
};
Push(features, feat);
}
var combinedDict = {
fields: [
{ name: 'team_name', type: 'esriFieldTypeString' },
{ name: 'length_by_team', type: 'esriFieldTypeDouble' },
],
geometryType: '',
features: features,
};
// Return dictionary cast as a feature set
return FeatureSet(Text(combinedDict));