Hi,
I'm trying to create a table that looks like the table below based on a date field called Inspect_Date. I just want to extract the year from the record and then have a count of those records. It would look like below.
I know the arcade code to pull the layer data and then code to turn it into a dictionary. Where I'm struggling is turning that dictionary into the table below.
Inspection Year | Inspection Count |
2024 | 442 |
2025 | 8 |
Code so far after getting the data:
Solved! Go to Solution.
You just need to make a minor change on line 23
var yearCounts = {}
// Count inspections by year
for (var f in fs) {
var inspDate = f["Inspect_Date"]
if (!IsEmpty(inspDate)) {
var year_1 = Text(Year(inspDate))
if (HasKey(yearCounts, year_1)) {
yearCounts[year_1] += 1
} else {
yearCounts[year_1] = 1
}
}
}
// Construct output features using Feature()
var features = []
for (var y in yearCounts) {
var attrs = {
"Year": y,
"Inspection_Count": yearCounts[y]
}
Push(features, {attributes: attrs})
}
// Return a proper FeatureSet
var schem = {
fields: [
{ name: "Year", type: "esriFieldTypeString" },
{ name: "Inspection_Count", type: "esriFieldTypeInteger" }
],
geometryType: "",
features: features
}
return FeatureSet(schem)
You just need to make a minor change on line 23
var yearCounts = {}
// Count inspections by year
for (var f in fs) {
var inspDate = f["Inspect_Date"]
if (!IsEmpty(inspDate)) {
var year_1 = Text(Year(inspDate))
if (HasKey(yearCounts, year_1)) {
yearCounts[year_1] += 1
} else {
yearCounts[year_1] = 1
}
}
}
// Construct output features using Feature()
var features = []
for (var y in yearCounts) {
var attrs = {
"Year": y,
"Inspection_Count": yearCounts[y]
}
Push(features, {attributes: attrs})
}
// Return a proper FeatureSet
var schem = {
fields: [
{ name: "Year", type: "esriFieldTypeString" },
{ name: "Inspection_Count", type: "esriFieldTypeInteger" }
],
geometryType: "",
features: features
}
return FeatureSet(schem)