t = table(1..10000 as rows ,take(2021.09.29, 10000)as date, rand(100, 10000) as v) mid = select max(v), imax(v) from t group by segment(v>=minV) mid = select * from mid where max_v >= minV ret = table(t.rows[mid.segment + mid.imax_v] as rows, t.date[mid.segment] as date, mid.max_v as max_v)