I have a dataset that includes a list of countries with the different studies done in those countries, and I want to auto calculate the number of studies per country in a new field.
I have used the Arcade GroupBY function as follows: GroupBy($layer,'COUNTRY', {name:'NumberS', expression:'Title', statistic:'COUNT'})
And I get this error: Cannot insert Object in Integer field. You can review the error in the script editor and try the calculation again, or cancel this calculation without changing any data.
Solved! Go to Solution.
You have a typo. It's "statistic" not "statistics"
GroupBy($layer, 'COUNTRY', { name:'NumberS', expression:'Title', statistic:'COUNT'})
Are you getting the same error or a different one?
@KenBuja I get this error: Cannot insert Object in Integer field. You can review the error in the script editor and try the calculation again, or cancel this calculation without changing any data.
Without seeing your full code, it sounds like you're trying to save the results of the GroupBy function to your field. GroupBy returns a FeatureSet, which is an object. You have to get the count value from that FeatureSet to save to your field. This is an example from the Playground that shows different ways of getting the GroupBy count for either the first record in the FeatureSet or a specific record.
var fs = FeatureSetByPortalItem(
Portal("https://www.arcgis.com"),
// portal item id
"6200db0b80de4341ae8ee2b62d606e67",
0, // layer id
["*"], // fields to include
true // include or exclude geometry
);
//Get the count of how many records for each floor value
var group = GroupBy(fs, 'FLOORCOUNT', {name: 'Floors', expression: '1', statistic: 'Count'})
//return just the first record
//return firstRec = First(group).Floors
//return the count for a specific floor (3)
return First(Filter(group, 'FLOORCOUNT = 3')).Floors