Data Expressions using GroupBy and Filter

418
3
Jump to solution
10-27-2021 10:39 AM
Labels (1)
MollyVetter
New Contributor II

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_datelocationpeople
10/5/2021 16:00location_110
10/5/2021 16:00location_213
9/22/2021 16:00location_15
9/24/2021 16:00location_24

 

What I want returned:

data_datelocationpeople
10/5/2021 16:00location_110
10/5/2021 16:00location_213

 

Any help would be appreciated! Thanks!

Molly (she/hers)

1 Solution

Accepted Solutions
JohannesLindner
MVP Regular Contributor

Something like this?

var fs = FeatureSetByName(...)
var last_date = First(OrderBy(fs, "data_date DESC")).data_date
return Filter(fs, "data_date= @last_date")

Have a great day!
Johannes

View solution in original post

3 Replies
JohannesLindner
MVP Regular Contributor

Something like this?

var fs = FeatureSetByName(...)
var last_date = First(OrderBy(fs, "data_date DESC")).data_date
return Filter(fs, "data_date= @last_date")

Have a great day!
Johannes
MollyVetter
New Contributor II

Thanks so much Johannes! That worked! Just needed to use ">=" in the filter.

JohannesLindner
MVP Regular Contributor

Glad it worked. Please accept the answer, so that your question shows up as answered.


Have a great day!
Johannes
0 Kudos