How to dynamically increase or decrease limit value in Query of Google sheet

主宰稳场 提交于 2019-12-25 01:27:52

问题


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


来源:https://stackoverflow.com/questions/55040000/how-to-dynamically-increase-or-decrease-limit-value-in-query-of-google-sheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!