Looking for the right syntax to filter a featureset for the latest date after grouping by Name. The data comes from survey123, and is being used in a dashboard data expression.
var Myportal = Portal('https://arcgis.com/');
var fs = FeatureSetByPortalItem( Myportal, );
var fs_gp = GroupBy(fs, ['Name'], [{name: 'recentDate', expression: 'CreationDate', statistic: 'MAX' }]);
//************************
// Create empty dictionary
var dict = {
fields: [{name: 'Name', type: 'esriFieldTypeString'},
{name: 'Company, type: 'esriFieldTypeString'},
{name: 'Email', type: 'esriFieldTypeString'},
{name: 'CreationDate', type: 'esriFieldTypeDate'}],
geometryType: "",
features: [],
};
// Loop through processed feature set and store its attributes
var i = 0;
for (var s in fs_gp) {
var names = s["Name"];
var recent = date(s["recentDate"])
for (var d in Filter(fs, "Stakeholder_Name = @stakeholder AND DATEDIFF(S, CreationDate, @recent)= 0")){
dict.features[i++] = {
attributes: {
Name: names,
Company: d["Company "],
Village: d["Village"],
Email: d["Email"],
CreationDate: d["CreationDate"]
}
}
}
}
return FeatureSet(Text(dict));I believe the issue is in the filter statement. Assistance would be greatly appreciated, thank you.