How to get multiple last records by tag

Hi,

I have following data (below) in Influxdb 2.0 and want to find multiple lines where column requestdate is the latest. There might be two approaches

  1. Should be simmilar to |> last(column: “requestdate”) but to return multiple records when there are multiple columns with latest requestdate.

  2. Other option would be to group tables by requestdate but I can’ find how to keep only table with latest requestdate

#group,false,false,true,false,false,false,true
#datatype,string,long,string,dateTime:RFC3339,double,long,string
#default,mean,
,result,table,_field,_time,_value,requestdate,s2_cell_id
,0,feels_daytemp,2021-01-31T10:00:00Z,-9.67,1612085402,46ddc
,0,feels_daytemp,2021-02-01T10:00:00Z,-11.24,1612085402,46ddc
,0,feels_daytemp,2021-02-02T10:00:00Z,-11.92,1612085402,46ddc
,0,feels_daytemp,2021-02-03T10:00:00Z,-8.41,1612085402,46ddc
,0,feels_daytemp,2021-02-04T10:00:00Z,-11.39,1612085402,46ddc
,0,feels_daytemp,2021-02-05T10:00:00Z,-16.77,1612085402,46ddc
,0,feels_daytemp,2021-02-01T10:00:00Z,-11.24,1612083602,46ddc
,0,feels_daytemp,2021-02-02T10:00:00Z,-11.92,1612083602,46ddc
,0,feels_daytemp,2021-02-03T10:00:00Z,-8.41,1612083602,46ddc
,0,feels_daytemp,2021-02-04T10:00:00Z,-11.39,1612083602,46ddc
,0,feels_daytemp,2021-01-31T10:00:00Z,-9.81,1612083602,46ddc
,0,feels_daytemp,2021-02-05T10:00:00Z,-16.77,1612083602,46ddc
,0,feels_daytemp,2021-02-04T10:00:00Z,-11.39,1612081802,46ddc
,0,feels_daytemp,2021-02-03T10:00:00Z,-8.41,1612081802,46ddc
,0,feels_daytemp,2021-02-02T10:00:00Z,-11.92,1612081802,46ddc
,0,feels_daytemp,2021-02-01T10:00:00Z,-11.24,1612081802,46ddc
,0,feels_daytemp,2021-01-31T10:00:00Z,-9.62,1612081802,46ddc
,0,feels_daytemp,2021-02-05T10:00:00Z,-16.77,1612081802,46ddc
,0,feels_daytemp,2021-01-31T10:00:00Z,-9.67,1612081086,46ddc
,0,feels_daytemp,2021-02-01T10:00:00Z,-11.24,1612081086,46ddc
,0,feels_daytemp,2021-02-02T10:00:00Z,-11.92,1612081086,46ddc
,0,feels_daytemp,2021-02-03T10:00:00Z,-8.41,1612081086,46ddc
,0,feels_daytemp,2021-02-04T10:00:00Z,-11.39,1612081086,46ddc
,0,feels_daytemp,2021-02-05T10:00:00Z,-16.77,1612081086,46ddc

Expected result would be:

,0,feels_daytemp,2021-01-31T10:00:00Z,-9.67,1612085402,46ddc
,0,feels_daytemp,2021-02-01T10:00:00Z,-11.24,1612085402,46ddc
,0,feels_daytemp,2021-02-02T10:00:00Z,-11.92,1612085402,46ddc
,0,feels_daytemp,2021-02-03T10:00:00Z,-8.41,1612085402,46ddc
,0,feels_daytemp,2021-02-04T10:00:00Z,-11.39,1612085402,46ddc
,0,feels_daytemp,2021-02-05T10:00:00Z,-16.77,1612085402,46ddc

My answer to this question is to use scalar values Influx Docs . First find latest requestdateMax value and then look only for records matching it.

requestdateData = from(bucket: “WeatherForecast”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: ® => r["_measurement"] == “weather_fdata”)
|> keep(columns: [“requestdate”,“s2_cell_id”,"_time"])
|> max(column: “requestdate”)

requestdateArray = requestdateData
|> findColumn(fn: (key) => true,column: “requestdate”)

requestdateMax = requestdateArray[0]

WeatherData = from(bucket: “WeatherForecast”)
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: ® => r["_field"] == “feels_daytemp”)
|> filter(fn: ® => r[“requestdate”] == requestdateMax)
|> yield()