Task List of all previously un-listed tasks in Dataview

What I’m trying to do

Context: I have a series of pages that follow the name format “*Tasks”. Each page contains a dataview list of tasks from pages that possess a certain tag. The page itself shares the tag it’s in charge of listing the tasks for.

Intent: I now want a page that lists any tasks that DON’T have a dedicated “*Tasks” page. The way I intended to go about this was to somehow have a dataview query that filters out files that don’t share the same tags as my pre-existing “*Tasks” files, as these automatically wouldn’t have a dedicated “*Tasks” page for them.

Things I have tried

I’ve tried a snippet like the following, which while it doesn’t fail, also shows absolutely nothing although I’m pretty sure such tasks exist:

TABLE file.tags, file.ctime
FROM #continue 
WHERE !contains(file.path,this.file.path) AND any(contains(file.tags,contains(file.path,"Tasks").tags))
SORT file.mtime DESC

Searching for reference on this is quite difficult considering there isn’t a single word that describe what I want, and searching on the dataview help pages or google ends up with a lot of hits for individual words in the long-winded explanation I have to give.

This seems to be needing a double query. One to receive all the tags from the “*Tasks”-files, and another one to check tasks not being tagged with any of those tasks. To achieve this I do believe we need to use dataviewjs in order to pass the result from one query to the other. Is it a lot of tags? And there are none tags in the “*Tasks”-files other than those used to match the tasks?

The following script seems to get all my non-tagged tasks in my test vault:

```dataviewjs

const taskTags = await dv.query(`
  LIST 
  WHERE file.tasks
  FLATTEN file.tasks as task
  FLATTEN task.tags as ttag
  GROUP BY ttag
`)

// Bail out if previous query failed
if ( ! taskTags.successful ) {
  dv.paragraph("~~~~\n" + taskTags.error + "\n~~~~")
  return
}

dv.list(taskTags.value.values)

const result = await dv.query(`
  TASK 
  FROM !(${ 
   taskTags.value.values.join(" OR ")
  } )
`)
  
if ( result.successful ) {
  dv.taskList(result.value.values)
} else
  dv.paragraph("~~~~\n" + result.error + "\n~~~~")
```

Before running this on a larger vault, I would strongly suggest to adapt that first query to something more sensible in your context. Maybe something similar to this:

```dataviewjs
  LIST
  FROM #continue
  WHERE endswith(file.name, "Tasks") 
  WHERE file.tasks
  FLATTEN file.tasks as task
  FLATTEN task.tags as ttag
  GROUP BY ttag
```

And if possible, instead of scanning the entire vault for tasks, any limitation on the latter query would also be useful to avoid building a query which breaks the Dataview query parser (which I think I did when I tried doing this query on all the tags in my test vault :smiley: )

1 Like

Thank you for the very detailed reply! I’m still very new to dataview so I’ll work through it slowly and get back to you when I’ve parsed your advice properly. Thank you!