Hi -
I have the following data expression in my dashboard and it is working perfectly, however my users want to be able to filter this chart by "watershed", which is not currently possible because this is not a field in my data or data expression. I have a separate hosted feature layer for watersheds that I will use to determine this.
I've used "Intersects" to calculate values in Field Maps & to show additional information in pop-ups, but I am not sure where exactly I should be fitting it into this expression to get what I want, which is a table that has a count of inspections, with their project ID and watershed.
Please see below.
This is my existing data expression that is working well:
// Create a FeatureSet for stable and unstable inspections.
// Group the features by the CGP file number
// Create filtered feature set for stable inspection points
var filterStablePts = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 1, ['Point_Status', 'SV_CGP_File_Number'], true), "Point_Status = 'Stable'");
var StablePts = GroupBy(filterStablePts,
["SV_CGP_File_Number"],
[
{name: "stable", expression: "Point_Status", statistic: "count"},
]
);
// Create filtered feature set for unstable inspection points
var filterUnstablePts = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 1, ['Point_Status', 'SV_CGP_File_Number'], true), "Point_Status = 'Unstable'");
var UnstablePts = GroupBy(filterUnstablePts,
["SV_CGP_File_Number"],
[
{name: "unstable", expression: "Point_Status", statistic: "count"},
]
);
// Create filtered feature set for general observation points
var filterObsPts = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 1, ['Point_Status', 'SV_CGP_File_Number'], true), "Point_Status = 'General Obs.'");
var ObsPts = GroupBy(filterObsPts,
["SV_CGP_File_Number"],
[
{name: "observation", expression: "Point_Status", statistic: "count"},
]
);
// Create filtered feature set for stable revisit (table) records
var filterStableRevis = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 3, ['R_Point_Status', 'R_CGP_File_Number'], true), "R_Point_Status = 'Stable'");
var StableRevis = GroupBy(filterStableRevis,
["R_CGP_File_Number"],
[
{name: "stablerevis", expression: "R_Point_Status", statistic: "count"},
]
);
// Create filtered feature set for unstable revisit (table) records
var filterUnstableRevis = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 3, ['R_Point_Status', 'R_CGP_File_Number'], true), "R_Point_Status = 'Unstable'");
var UnstableRevis = GroupBy(filterUnstableRevis,
["R_CGP_File_Number"],
[
{name: "unstablerevis", expression: "R_Point_Status", statistic: "count"},
]
);
// Create an empty dictionary to hold the data
var combinedDict = {
fields: [
{name: "File_Number", type: "esriFieldTypeString"},
{name: "Pt_Status", type: "esriFieldTypeString"},
{name: "Num_Inspections", type: "esriFieldTypeInteger"},
],
geometryType: "",
features: [],
};
// Fill the new dictionary with data
var i = 0;
// Loop through features and parse them into appropriate fields within dictionary
// Stable point inspections
for (var m in StablePts) {
combinedDict.features[i] = {
attributes: {
File_Number: m["SV_CGP_File_Number"],
Pt_Status: "Stable",
Num_Inspections: m["stable"],
},
};
i++;
}
// Unstable point inspections
for (var n in UnstablePts) {
combinedDict.features[i] = {
attributes: {
File_Number: n["SV_CGP_File_Number"],
Pt_Status: "Unstable",
Num_Inspections: n["unstable"],
},
};
i++;
}
// General observation points
for (var q in ObsPts) {
combinedDict.features[i] = {
attributes: {
File_Number: q["SV_CGP_File_Number"],
Pt_Status: "General Observation",
Num_Inspections: q["observation"],
},
};
i++;
}
// Stable revisit records (table)
for (var o in StableRevis) {
combinedDict.features[i] = {
attributes: {
File_Number: o["R_CGP_File_Number"],
Pt_Status: "Stable Revisit",
Num_Inspections: o["stablerevis"],
},
};
i++;
}
// Unstable revisit records (table)
for (var p in UnstableRevis) {
combinedDict.features[i] = {
attributes: {
File_Number: p["R_CGP_File_Number"],
Pt_Status: "Unstable Revisit",
Num_Inspections: p["unstablerevis"],
},
};
i++;
}
return FeatureSet(Text(combinedDict));
This is where I am with adding in the Intersects piece - I've tried a few different things in different places within here, but I can't figure out where this should go/how to incorporate it. We have a separate Watersheds hFL which I am attempting to intersect against. See lines 67, 68, 81 below.
// Create a FeatureSet for stable and unstable inspections.
// Group the features by the CGP file number
// Create filtered feature set for stable inspection points
var filterStablePts = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 1, ['Point_Status', 'SV_CGP_File_Number'], true), "Point_Status = 'Stable'");
var StablePts = GroupBy(filterStablePts,
["SV_CGP_File_Number"],
[
{name: "stable", expression: "Point_Status", statistic: "count"},
],
);
// Create filtered feature set for unstable inspection points
var filterUnstablePts = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 1, ['Point_Status', 'SV_CGP_File_Number'], true), "Point_Status = 'Unstable'");
var UnstablePts = GroupBy(filterUnstablePts,
["SV_CGP_File_Number"],
[
{name: "unstable", expression: "Point_Status", statistic: "count"},
]
);
// Create filtered feature set for general observation points
var filterObsPts = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 1, ['Point_Status', 'SV_CGP_File_Number'], true), "Point_Status = 'General Obs.'");
var ObsPts = GroupBy(filterObsPts,
["SV_CGP_File_Number"],
[
{name: "observation", expression: "Point_Status", statistic: "count"},
]
);
// Create filtered feature set for stable revisit (table) records
var filterStableRevis = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 3, ['R_Point_Status', 'R_CGP_File_Number'], true), "R_Point_Status = 'Stable'");
var StableRevis = GroupBy(filterStableRevis,
["R_CGP_File_Number"],
[
{name: "stablerevis", expression: "R_Point_Status", statistic: "count"},
]
);
// Create filtered feature set for unstable revisit (table) records
var filterUnstableRevis = Filter(FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '12345x', 3, ['R_Point_Status', 'R_CGP_File_Number'], true), "R_Point_Status = 'Unstable'");
var UnstableRevis = GroupBy(filterUnstableRevis,
["R_CGP_File_Number"],
[
{name: "unstablerevis", expression: "R_Point_Status", statistic: "count"},
]
);
// Create an empty dictionary to hold the data
var combinedDict = {
fields: [
{name: "File_Number", type: "esriFieldTypeString"},
{name: "Pt_Status", type: "esriFieldTypeString"},
{name: "Num_Inspections", type: "esriFieldTypeInteger"},
{name: "Watershed", type: "esriFieldTypeString"},
],
geometryType: "",
features: [],
};
// Feature set for watershed intersection
var watersheds = FeatureSetByPortalItem(Portal('https://mass-eoeea.maps.arcgis.com'), '4a7abb05f6eb42d78e31587b05e3ebec', 0, ['Label_Field'], false);
var watershed = First(Intersects(combinedDict,watersheds));
// Fill the new dictionary with data
var i = 0;
// Loop through features and parse them into appropriate fields within dictionary
// Stable point inspections
for (var m in StablePts) {
combinedDict.features[i] = {
attributes: {
File_Number: m["SV_CGP_File_Number"],
Pt_Status: "Stable",
Num_Inspections: m["stable"],
Watershed: m[watershed],
}],
},
};
i++;
}
// Unstable point inspections
for (var n in UnstablePts) {
combinedDict.features[i] = {
attributes: {
File_Number: n["SV_CGP_File_Number"],
Pt_Status: "Unstable",
Num_Inspections: n["unstable"],
},
};
i++;
}
// General observation points
for (var q in ObsPts) {
combinedDict.features[i] = {
attributes: {
File_Number: q["SV_CGP_File_Number"],
Pt_Status: "General Observation",
Num_Inspections: q["observation"],
},
};
i++;
}
// Stable revisit records (table)
for (var o in StableRevis) {
combinedDict.features[i] = {
attributes: {
File_Number: o["R_CGP_File_Number"],
Pt_Status: "Stable Revisit",
Num_Inspections: o["stablerevis"],
},
};
i++;
}
// Unstable revisit records (table)
for (var p in UnstableRevis) {
combinedDict.features[i] = {
attributes: {
File_Number: p["R_CGP_File_Number"],
Pt_Status: "Unstable Revisit",
Num_Inspections: p["unstablerevis"],
},
};
i++;
}
return FeatureSet(Text(combinedDict));
Any help would be appreciated. I've never tried this in a data expression with GroupBy statements before and feel like I am missing something fundamental here.
Thank you,
Erica