Get first time of a cycle for Grouped Columns and then downsample into new bucket

Just wrapping my brain around fluxlang for the first time and I’m quite stuck. Situation is: I have a flux bucket collecting data from sensors:

  • RSSI
  • CycleId
  • Channel (Radio Channel)
  • SensorId
  • Mac
  • _time
    …among other things that don’t matter so much for this example

I want to grab the first time the sensor has seen the device per cycle (as opposed to based on a time slice).

Here is my current code but I’m stumped as to how to just grab the first timestamp. I’d love to just group against CycleID, DeviceID, Mac, and grab the RSSI at the min(_time) but I’m struggling.
Thing is aggregateWindow requires a time-based aggregation which isn’t what I need, and group by doesn’t have any accompanying aggregation.

Here is what I’ve got so far.

from(bucket: "PresenceSensor_MacScan")
|> range(start: -12h)
|> filter(fn: (r) => r["_field"] == "RSSI" or r["_field"] == "Channel"  or r["_field"] == "Mac2")
|> pivot(rowKey:["_time","device"], columnKey: ["_field"], valueColumn: "_value")
|> drop(columns: ["_start", "_stop","_measurement"])
|> group(columns: ["device", "Channel", "Mac2"])
|> min( column: "_time")

Update: I’ve updated the above with what I think is the answer. Challenge is that when I try and push that data into a new bucket - it won’t go. Influx wants a field called “_field”. Which I don’t have.

I’ve tried playing around with ways to unpivot, to no success, and I’ve tried thinking of other ways to find the min time of a group of columns (avoiding pivots) but no luck so far.

Hello @Timmwardion,
You can add a _field column. I think that’s probably the simplest solution
Use any of these functions to do so: