Turn simple query for this week tasks into advanced query

Hello, I have this simple query that searches for incomplete tasks in this week journal’s pages. Take [[Week 16]] for example.

{{query (and (task TODO LATER DOING WAITING) (or (page [[2024/04/15 Mon]]) (page [[2024/04/16 Tue]]) (page [[2024/04/17 Wed]]) (page [[2024/04/18 Thu]]) (page [[2024/04/12 Fri]]) (page [[2024/04/13 Sat]]) (page [[2024/04/21 Sun]])))}}

That query is long so I want to tranform it into advanced query to remove cluttered space. I tried following one but it shows to be invalid:

#+BEGIN_QUERY
{:title [:b "Incompleted Tasks"]
:query (and (task TODO LATER DOING WAITING) (or ([[2024/04/15 Mon]]) ([[2024/04/16 Tue]]) ([[2024/04/17 Wed]]) ([[2024/04/18 Thu]]) ([[2024/04/12 Fri]]) ([[2024/04/13 Sat]]) ([[2024/04/21 Sun]])))
}
#+END_QUERY

I also format my journal pages as “YYYY/MM/DD EEE”. Above advanced query only works for “2024/04”, “2024/03”, etc but not for “2024/04/18 Thu”.

  :journal/page-title-format "YYYY/MM/DD EEE"
  :journal/file-name-format "YYYY/MM/DD EEE"

Any help is appreciated. Thanks in advanced.

Welcome. Try something like this:

#+BEGIN_QUERY
{:title [:b "Incompleted Tasks"]
 :query [:find (pull ?b [*])
   :where
     [?b :block/marker ?marker]
     [(contains? #{"TODO" "LATER" "DOING" "WAITING"} ?marker)]
     [?b :block/page ?p]
     (or
       [?p :block/name "2024/04/15 mon"]
       [?p :block/name "2024/04/16 tue"]
       [?p :block/name "2024/04/17 wed"]
       [?p :block/name "2024/04/18 thu"]
       [?p :block/name "2024/04/12 fri"]
       [?p :block/name "2024/04/13 sat"]
       [?p :block/name "2024/04/21 sun"]
     )
 ]
}
#+END_QUERY
1 Like

Thank you for your quick assistance, mentaloid. Unforturnately, the advanced query fails to show results. To clarify, I want to filter tasks that lives inside specific journal pages like below. Can you please help me again?

[[2024/04/15 Mon]]
- TODO task 1

[[2024/04/16 Tue]]
- review [[project X]]
 - TODO task 2

etc.


I have updated my answer accordingly.

1 Like

Thank you mentaloid it works perfecty!