How to query scheduled/overdue tasks, that are not done yet?

First I queried all scheduled (or deadline) tasks that are overdue or scheduled in next 30 days:

#+BEGIN_QUERY
{:query [:find (pull ?block [*])
          :in $ ?next
          :where
          (or
            [?block :block/scheduled ?d]
            [?block :block/deadline ?d]
          )
          [(< ?d ?next)]
  ]
  :inputs [:30d-after]
  :collapsed? false}
#+END_QUERY

This works, but I have no way to filter out those, that are already marked as DONE.

What I tried in next step: take all scheduled tasks, which haven’t any marker at all or, if existent, do not contain the DONE marker:

#+BEGIN_QUERY
{:title [:b "SCHEDULED, DEADLINE: Overdue and next 30 days "]
  :query [:find (pull ?block [*])
          :in $ ?next
          :where
          (or
            [?block :block/scheduled ?d]
            [?block :block/deadline ?d]
          )
          (or
            (not [?block :block/marker])
            (and 
              [?block :block/marker ?marker]
              (not [(contains? #{"DONE"} ?marker)])
            )
          )
          [(< ?d ?next)]
  ]
  :inputs [:30d-after]
  :collapsed? false}
#+END_QUERY

, which raises a block render error. Any help on this? Error seems to be with:

          (or
            (not [?block :block/marker])
            (and 
              [?block :block/marker ?marker]
              (not [(contains? #{"DONE"} ?marker)])
            )
          )
1 Like

Found solution:

(not
  [?b :block/marker ?marker] 
  [(contains? #{"DONE"} ?marker)]
 )

I am trying to do exactly this, but I am confused where your solution code goes. Can you post your complete code working?

?b should be ?block, which would result like this:

#+BEGIN_QUERY
{:title [:b "SCHEDULED, DEADLINE: Overdue and next 30 days"]
  :query [:find (pull ?block [*])
    :in $ ?next
    :where
    (or
      [?block :block/scheduled ?d]
      [?block :block/deadline ?d]
    )
    (not
      [?block :block/marker ?marker] 
      [(contains? #{"DONE"} ?marker)]
    )
    [(< ?d ?next)]
  ]
  :inputs [:30d-after]
  :collapsed? false
}
#+END_QUERY
1 Like

This is wonderful. Thank you for the quick reply. This is exactly what I needed.

For everyone’s interest I guess, more task related queries can be found here: