Advanced Query: showing "TODO"s with a deadline AND [(not scheduled) OR (scheduled <= today)]

I’m pretty new in query and have tried to modify several query examples, unfortunately, I still failed to get the result I’m looking for. Can anyone help me to write an advanced query showing this result?
:arrow_down::arrow_down:
“showing blocks marked as “TODO” with a deadline AND [(not scheduled) OR (scheduled <= today)]”

p.s. preferred to be an “advanced query”(so that I can learn from how you formulate the syntax) rather than a simple query.

Many Thanks!

1 Like

I have the same problem and also I really want this query to apperar every day in my journal pages since I like to have an overview of my meetings and tasks for each day

I just managed to solve this recently.

Below are the default queries I am using to follow a deadline-driven task-surfacing approach.

;; The app will show those queries in today's journal page,
 ;; the "NOW" query asks the tasks which need to be finished "now",
 ;; the "NEXT" query asks the future tasks.
 :default-queries
 {:journals [
   {:title "🔨 DAILY"
    :query [:find (pull ?h [*])
            :where
            [?h :block/marker ?marker]
            [(contains? #{"NOW" "DOING"} ?marker)]
            [?t :block/name "daily"]
            [?h :block/refs ?t]
            [?h :block/page ?p]
            [?p :block/journal? true]
           ]
    :inputs []
    :result-transform (fn [result] (sort-by (fn [h] (get h :block/deadline)) result))
    :collapsed? false}

   {:title "🔨 NOW"
    :query [:find (pull ?h [*])
            :where
            [?h :block/marker ?marker]
            [(contains? #{"NOW" "DOING"} ?marker)]
            (not [?t :block/name "daily"]
            [?h :block/refs ?t])
            [?h :block/page ?p]
            [?p :block/journal? true]
           ]
    :inputs []
    :result-transform (fn [result] (sort-by (fn [h] (get h :block/deadline)) result))
    :collapsed? false}

   {:title "📅 WAITING"
    :query [:find (pull ?h [*])
            :in $ ?next
            :where
            [?h :block/marker ?marker]
            [(contains? #{"WAITING"} ?marker)]
            [?h :block/page ?p]
            [?p :block/journal? true]
            [?h :block/deadline ?d]
            [(< ?d ?next)]
           ]
    :inputs [:7d-after]
    :result-transform (fn [result] (sort-by (fn [h] (get h :block/deadline)) result))
    :collapsed? true}

   {:title "📅 BACKLOG"
    :query [:find (pull ?h [*])
            :in $ ?next
            :where
            [?h :block/marker ?marker]
            [(contains? #{"LATER" "TODO"} ?marker)]
            [?h :block/page ?p]
            [?p :block/journal? true]
            [?h :block/deadline ?d]
            [(< ?d ?next)]
           ]
    :inputs [:7d-after]
    :result-transform (fn [result] (sort-by (fn [h] (get h :block/deadline)) result))
    :collapsed? true}
 ]}

Add above to your config.edn.

(Caution, each graph might have its config.edn)