Dataview query to create list of tasks from under specific headings of page

What I’m trying to do

I have this little code which currently pulls together any unchecked tasks on a page:

WHERE file = this.file
WHERE !completed

I’d like to limit the search to only two headers:

The headers: ‘## 6 Priorities\’ and ‘## Brain Dump\’

Things I have tried

I think the code might be something sort of like this (although without a link)
WHERE header = [[File#Header]]

I also have a similar dataviewjs query that does the same thing, but similar problems (I don’t know how to target the two specific headers)

dv.taskList((dv.current().file.tasks).where(t => !t.completed))

For this one, I was playing around with this code:

  .flatMap(page => page.file.tasks.where(t => t.section.subpath == "6 Priorities" and "Brain Dump")))

The idea is to basically allow myself to brainstorm and create action items along the way, and then have them all collect on one part of the page so I can easily reference them and figure out what to focus on moving forward. Both current codes are okayish but they are still pulling tick boxes from parts of the page that I don’t want included.

Thanks for your help!

So just to follow-up I ended up eventually finding parts of the answer online and getting something to work. I now have codes that work for both options:

  .filter(t => (t.section.subpath === "Brain Dump" || t.section.subpath === "6 Priorities") && !t.completed)

WHERE file = this.file
WHERE (meta(header).subpath = "Brain Dump" OR meta(header).subpath = "6 Priorities") AND !completed

Sharing in case it ends up being helpful to anyone else!

Also, I realized the moment that I started adding sub-headers underneath headers, that the code stopped to retrieving data. So I asked my friend ChatGPT and now we have these solutions that target multiple headers and sub-headers:

  .filter(t => 
    (t.section.subpath === "Brain Dump" || 
     t.section.subpath === "6 Priorities" || 
     t.section.subpath === "Life" || 
     t.section.subpath === "Family" || 
     t.section.subpath === "Work" || 
     t.section.subpath === "Health"
    ) && !t.completed


WHERE file = this.file
  meta(header).subpath = "Brain Dump" 
  OR meta(header).subpath = "6 Priorities" 
  OR meta(header).subpath = "Life" 
  OR meta(header).subpath = "Family" 
  OR meta(header).subpath = "Work" 
  OR meta(header).subpath = "Health"
) AND !completed

The latter DQL query’s WHERE clause could also be written something like:

WHERE econtains(
    list(  "Brain Dump", "6 Priorities", "Life", "Family", "Work", "Health"),
    meta(header).subpath) )
  AND !completed

Similar options predefining the array exists also for dataviewjs, which also there would lead to slightly more readable code.

1 Like

I appreciate this - it definitely looks a lot nicer!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.