Select to view content in your preferred language

Create feature view of latest record using group by

193
2
Sunday
GISNCC
by
Regular Contributor

Hi, 

This has stumped me for awhile.  I have a feature class with points (inspections) on various properties with a unique property ID.  I want to create a feature view of just the latest inspection point for each property.  (Note there is no related table in use in this example).  So basically create a feature view using a group by clause on the Property ID, and pull out record based on the latest inspection date.

 

I have just found the following which is fantastic and solves my problem finally. 

https://community.esri.com/t5/arcgis-online-documents/display-latest-feature-in-a-feature-service/ta...

I was wondering however if there was any way to do this with arcade?  (Arcade is probably more familiar and easier for others to use if they need to maintain/update this).   There doesn't appear to be any arcade functionality in the filter option when creating a view layer.  I tried the arcade expressions in the symbology of the map but I couldn't get the syntax working (and also probably not as preferable as a feature view layer). 

Thanks,

Karyn

0 Kudos
2 Replies
MErikReedAugusta
MVP Regular Contributor

Off the top of my head, your best bet is likely to be the FeatureSetByName and related functions, but the first potential problem will be whether you're running this code in one of the areas that actually has access to that function.  Arcade is actually about a half-dozen partially-separate implementations of the same base language, and what functions are available is highly dependent on the context in which you're running Arcade and what "profile" is available.

If I were wanting to do this in something like an Attribute Rule, I'd probably write something roughly along the lines of the following:

/* Return All Inspections for All Properties, first
   N.B., we limit this pull to just the fields you absolutely need, and
   we turn off the geometry import, unless you absolutely need it.  Both
   are to increase the efficiency of the call, but whether you can get away
   with them will depend on the context where this is running.
*/
var allInspections = FeatureSetByName($datastore, 'FeatureName', ['PropertyID'], false)

/* We filter the result down to the ONE inspection with the most recent date
   for the property in question.  This might require some sort of iteration,
   though, and the tricky part will be balancing database calls.  Keeping
   First() out will help, but it might not be the only function like that.
   My memory is a little foggy, and I'm away from my machine right now.
*/
var propInspections = OrderBy(Filter(allInspections, "PropertyID == 'InputPropertID'"), 'InspectionDate DESC')

return First(propInspections)

 

But when we've tried similar commands in Calculated Expressions in Field Maps, for example, many of those FeatureSet functions aren't actually available, and similar problems.  Symbology is another area where functions tend to be heavily restricted, for example, because ESRI deemed the demands on the symbology engine to be too excessive.  So whether it's possible will most likely depend on whether ESRI felt exposing the function to the profile in question was an "acceptable use of resources".

------------------------------
M Reed
"The pessimist may be right oftener than the optimist, but the optimist has more fun, and neither can stop the march of events anyhow." — Lazarus Long, in Time Enough for Love, by Robert A. Heinlein
GISNCC
by
Regular Contributor

Hi, Thanks very much for that explanation.  Its good to know about how it works in terms of different things being exposed in the various tools/engines and makes sense.  Cheers,

0 Kudos