Does Groupby() have the ability to concatenate fields as the they are grouped? Seems like this should be easier but I can't find any documentation.
The results would be groupby(date), count, concat(field_value).
Here's one I use to concatenate fields. It uses GroupBy to get the required fields and counts, then creates a new featureset with the concatenated fields.
My original dataset has the field Strat_Num, which is a unique combination of Habitat, Depth, Subregion, and Admin.
I wanted to group by Stratum Number, concatenate the other values, and get their count.
This is the code I came up with
var fs = FeatureSetByPortalItem( Portal("https://www.arcgis.com/"), "itemId", 0 ); var grouped = GroupBy( fs, "Strat_Num", [ { name: "Habitat", expression: "Habitat", statistic: "Max" }, { name: "Depth", expression: "Depth", statistic: "Max" }, { name: "SUBREGION", expression: "SUBREGION", statistic: "Max" }, { name: "ADMIN", expression: "ADMIN", statistic: "Max" }, { name: "Count", expression: "1", statistic: "Count" } ] ); var features = []; for (var i of grouped) { Push( features, { attributes: { Number: i.Strat_num, Stratum: `${i.Habitat} ${i.Depth} ${i.SUBREGION} ${i.Admin}`, Count: i.Count } } ); } return FeatureSet( { fields: [ { name: "Number", type: "esriFieldTypeInteger" }, { name: "Stratum", type: "esriFieldTypeString" }, { name: "Count", type: "esriFieldTypeInteger" } ], features: features } );
which gives me this table
Aangemelde leden kunnen berichten plaatsen, updates volgen en meer. Nieuw hier? Registreer een gratis account.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.