How to dynamically increase or decrease limit valu

2019-08-17 19:18发布

问题:

So my task is to get last x rows based on some count calculation and for that, I'm using limit offset in a query. To elaborate more, I have this formula that works fine

=COUNTIF(QUERY(A:A,"limit 5 offset "&(COUNT(A:A)-5),A1)>1

The problem here is that I don't want to "Hardcode" that value of "5" since my range changes based on the count of some timestamp function I'm using on another column. SO I made some changes in above formula by adding another count function that checks the other column and changes range each time.

=COUNTIF(QUERY(A:A,"limit COUNT(FILTER(D:D,D:D>NOW()-6/24)) offset "&(COUNT(A:A)-COUNT(FILTER(D:D,D:D>NOW()-6/24)))),A1)>1 

The main issue in this formula is this line

"limit COUNT(FILTER(D:D,D:D>NOW()-6/24)) offset "

as I can't use count function in limit+offset apparently. How can I change the syntax to run limit, offset query?

Edit: This doesn't work as well

"limit"+COUNT(FILTER(D:D,D:D>NOW()-6/24))+"offset"

回答1:

try like this:

=COUNTIF(QUERY(A:A,
 "limit "&COUNT(FILTER(D:D,D:D>NOW()-6/24))&" 
  offset "&(COUNT(A:A)-COUNT(FILTER(D:D,D:D>NOW()-6/24)))),A1)>1