Hi,
I've got a data set that includes data for two different locations ("location" field, string) and I'm trying to create a data expression that returns the number of people ("people" field, integer) at each location based on the most recent record ("data_date" field, date) for each location.
I've looked at the GitHub examples for GroupBy and MostRecentRecord and I think I need to kind of combine these but haven't had any luck so far.
Data:
data_date | location | people |
10/5/2021 16:00 | location_1 | 10 |
10/5/2021 16:00 | location_2 | 13 |
9/22/2021 16:00 | location_1 | 5 |
9/24/2021 16:00 | location_2 | 4 |
What I want returned:
data_date | location | people |
10/5/2021 16:00 | location_1 | 10 |
10/5/2021 16:00 | location_2 | 13 |
Any help would be appreciated! Thanks!
Molly (she/hers)
Solved! Go to Solution.
Something like this?
var fs = FeatureSetByName(...)
var last_date = First(OrderBy(fs, "data_date DESC")).data_date
return Filter(fs, "data_date= @last_date")
Something like this?
var fs = FeatureSetByName(...)
var last_date = First(OrderBy(fs, "data_date DESC")).data_date
return Filter(fs, "data_date= @last_date")
Thanks so much Johannes! That worked! Just needed to use ">=" in the filter.
Glad it worked. Please accept the answer, so that your question shows up as answered.