Advanced Queries - Deadline and Scheduled not playing along with other types of blocks?

I have a query for tasks referencing future date.
And wanted to add also blocks with /deadline or /schedule of future date.

How can I make them play nicely together?

I created the monster below to test it. The 3rd AND operator on it’s own works, and the first two together as well. Mixing them always returns 0 results. What am I missing?

#+BEGIN_QUERY
{:title "🟠 NEXT TO PLAY"
    :query [:find (pull ?h [*])
            :in $ ?today ?next
            :where (or (and [?h :block/scheduled ?d]
                                        [(>= ?d ?today)]
                                        [(<= ?d ?next)])
                                (and [?h :block/deadline ?d]
                                        [(>= ?d ?today)]
                                        [(<= ?d ?next)])
                                (and [?h :block/marker ?marker]
                                          [?h :block/path-refs ?p]
                                         [?p :page/journal? true]
                                         [?p :page/journal-day ?d]
                                         [(contains? #{"NOW" "DOING" "TODO" "LATER" "WAITING"} ?marker)]
                                         [(>= ?d ?today)]
                                         [(<= ?d ?next)])
)
]
    :inputs [:1d-after :30d-after]
    :result-transform (fn [result]
                        (sort-by (fn [h]
                                   (get h :block/priority "Z")) result))
    :collapsed? false}
#+END_QUERY
3 Likes

My schedule task is like this

#+BEGIN_QUERY
{
	:title "🍻 It's time to make it happen"
    :query [
    	:find (pull ?h [*])
        :in $ ?start ?next
        :where
        [?h :block/marker ?marker]
        [(contains? #{"NOW" "LATER" "TODO"} ?marker)]
        ;; filter by scheduled or deadline
        (or [?h :block/scheduled ?d] [?h :block/deadline ?d])
        [(>= ?d ?start)]
        [(< ?d ?next)]
    ]
  	:inputs [:today :7d-after]
    :result-transform (fn [result]
    					(sort-by (fn [h]
                        			(get h :block/priority "Z")) result))
    :collapsed? false}
#+END_QUERY

:smiley: Do you figure out how to make it work now?