I'm hoping I'm close! I was trying to do a similar thing using an Arcade Expression for symbology but I can't select the most recent feature. So instead I'm writing the data to a new Field using Forms.
I have two datasets, a point dataset of sampling locations, and a corresponding pond polygon layer.
The pond polygon layer will be public facing, and the symbology will reflect data gathered in the survey that populates the point feature class. I have created a new, blank field in the pond polygon feature class that I'm hoping I can populate given a few criteria from the point layer. Below is my arcade expression that I'm using in 'Forms' to calculate that blank field. I need the pond to correspond to the correct points (hence the buffer in case they are slightly outside of the polygon), and I need the dates of the samples to be within 30 days. As an option, if Intersect with a Buffer won't work, I do have an ID field that is identical between the point layer and the polygon layer.
// Define a Featureset (status) from the layer "Cyanobacteria_Public View" in the $map
// that contains the attribute ['cyano_risk_tier']
var status = FeatureSetByName($map, "Cyanobacteria_Public View", ['cyano_risk_tier', 'fluorometry_date', 'final_review'])
// Define a variable (risk) to store the value we want
// Get the value by Intersecting the pond polygon location
// with the FeatureSet "Cyano Ponds Public View", or status
var risk = Top(OrderBy(Intersects(status, Buffer($feature, 30, "meters")), 'fluorometry_date DESC'), 1);
var edit_datetime = Date(status['fluorometry date']);
var now_datetime = Now();
var days_dif = DateDiff(now_datetime, edit_datetime, "days");
// If the current location intersects the pond,
// return the value in the field ['cyano_status'].
// Otherwise, return a null value for areas where there is no intersecting polygon
var result = "No updated information";
if (!IsEmpty(risk) && (days_dif <30)) {
return risk['cyano_risk_tier']
} else {
return result
}
As a next step, if this works to populate the field in the pond polygon layer, I would also like to add on to this expression to allow for the following situations. Occasionally, there are two sample sites for the same pond in the same day. One sample site may have a lower 'cyano risk tier' than the other site. I would like to default the 'cyano_status' to the higher of the 2 risk tiers. So for example, if one sample site the risk is 'Acceptable', and at the second sample site the risk is 'Potential for Concern' (and these sites were sampled in the same day), I would need the overall risk for the pond to be 'Potential for Concern.' In total there are 3 risks in the tier.