Downsample data by not a constant time interval but a constant threshold on cumulative sum of a field value

Hi,

Is it possible to downsample data by not a constant time interval but a constant threshold on cumulative sum of a field value?

For example, I set a threshold as 1,000 and whenever cumulative sum of “volume” field hit this threshold, I sample the time series and return the downsampled time series at the end.

I am not sure how I can achieve this with Flux query.

Thanks.