Compare consecutive values of the same field

I have a question regarding a query for InfluxDB using the query-language flux. I have a measurement with two relevant fields, both of the type float. I managed to calculate a mean value for field_1 for a specific time range with the aggregateWindow function. now I need to add a condition to the statement, where I look at field_2 and exclude all values from the aggregation, where field_2 changed it’s own value. so, given this example:

time field_1 field_2
12:00:01 1.15 2.0
12:00:02 1.24 2.0
12:00:03 2.45 2.5
12:00:04 0.98 2.5

I would like to exclude the third value from the aggregation (which would be in this case field_1: 2.45), because field_2 changed its value (from 2.0 to 2.5). I found the function difference(last(value)) which could give me the difference for two consecutive values. but I haven’t found a way to use “difference” as a condition in a query, so I’m not sure if this is the right way to go. is there any way to do what I’m looking for here?