Dumb question, I know.
How to exclude “done tasks” in dataview task query?
Done tasks are those that look like this: - [x]
Dumb question, I know.
How to exclude “done tasks” in dataview task query?
Done tasks are those that look like this: - [x]
Does the sample file / query do what you want when added to Obsidian?
Angel
A task list.md (704 Bytes)
I like your query. Thank you.
One question.
Is there any method to exclude several files from the result?
```dataviewjs
dv.taskList(dv.pages("").file.tasks
.where(t => !t.completed))
```
With this query, the result includes the tasks from template files, for example.
If you had a specific folder to target, you could use the following query (in this example, the query references a folder called ‘films’ only):
```dataviewjs
dv.taskList(dv.pages('"films"').file.tasks
.where(t => !t.completed))
```
And if you wanted to exclude one folder, ‘films’ again in this example, you could use:
```dataviewjs
dv.taskList(dv.pages('-"films"').file.tasks
.where(t => !t.completed))
```
Does what you need?
Angel
In addition to exclude folders (as explained by @anon12638239), you can exclude files:
```dataviewjs
dv.taskList(dv.pages()
.file.where(f => f.name != "yourfilename 1")
.tasks.where(t => !t.completed))
```
```dataviewjs
dv.taskList(dv.pages()
.file.where(f => f.name != "yourfilename 1" && f.name != "yourfilename 2" && f.name != "yourfilename 3")
.tasks.where(t => !t.completed))
```
Angel & mnvwvnm,
Exactly, those are what I want to know.
Thank you for your replies.
For those who might want to exclude multiple folders,
```dataviewjs
dv.taskList(dv.pages('-"films" and -"music" and -"books"').file.tasks
.where(t => !t.completed))
```
worked for me.
Thanks to @mnvwvnm and @obsidian337.
Some questions to @mnvwvnm, if I may:
Why does your code for multiple files use paired ampersands? One ampersand seems to work okay. Better to use pairs?
Out of interest only, I have tried replacing the ampersands you used with ‘and’ (as used by @obsidian337 in their example for excluding multiple folders), but I can’t get ‘and’ to work. Queries for folders use ‘and’, but queries for files use ‘&’? Or am I doing something wrong?
Thanks
Angel
Thanks for the questions, but I don’t have clear answers for you.
I’m a ‘zero’ in the knowledge of Javascript language.
The results achieved are the result of two techniques: 1) learning from other posted codes in forum and 2) from “try and error” method (not from any skill for code or similar).
What I know?
dv.pages(source)
“takes a single string argument, source
, which is the same form as a query language source”, i.e., “#tags” and “folders”, not “files” (about “links” TO or FROM, I don’t know how to use them in JS). In these cases you can use the same “query language” (simple dataview queries language). For “files” I just found the solution via file name
… and for “WHERE” filter command the valid logical operator for AND seems to be “&&”.A zero? If that is the case, clearly a zero with a brilliant mind and a generous spirit.
Thank you very much for the answers. I will digest what you have said, and I will read Colin’s blog a few times until everything has sunk into the mud that is my mind.
Ciao.
Angel
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.