Just answered on the Idea you posted. Ideas are for improvements you want to propose. Let's talk about this question here.
You have to join the Variant field to the grouped Featureset. There is no native function to join a field, so you have to do it yourself:
// group by date and site, getting the max frequency
var grouped_fs = GroupBy(fs, ['Sample_Date', 'Site_ID'], [{name: 'Estimated_Frequency_Reads', expression: 'Estimated_Frequency_Reads', statistic: 'MAX' }] )
// create an empty featureset for the join with variant
var join_fields = [
{name: "Variant", type: "esriFieldTypeString"}
]
var out_fs = {
geometryType: "",
fields: Splice(Schema(grouped_fs).fields, join_fields),
features: []
}
// join with the original fs to get the variant
for(var f in grouped_fs) {
var d = f.Sample_Date
var s = f.Site_ID
var f = f.Estimated_Frequency_Reads
var join = First(Filter(fs, "Sample_Date = @d AND Site_ID = @s AND Estimated_Frequency_Reads = @f"))
Push(out_fs.features, {attributes:{Sample_Date: Number(d), Site_ID: s, Estimated_Frequency_Reads: f, Variant: join.Variant}})
}
return Featureset(Text(out_fs))
This expression uses Filter() in a loop, which isn't very performant. If the expression is slow, copy the Memorize() function from this blog post and apply it to your Featureset:
var fs = Memorize(FeaturesetByPortalItem(...))
Have a great day!
Johannes