How to exclude "done tasks" in dataview task query

Dumb question, I know.

How to exclude “done tasks” in dataview task query?

Done tasks are those that look like this: - [x]

1 Like

Does the sample file / query do what you want when added to Obsidian?

Angel

A task list.md (704 Bytes)

1 Like

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

6 Likes

In addition to exclude folders (as explained by @anon12638239), you can exclude files:

  1. exclude one file
```dataviewjs
dv.taskList(dv.pages()
.file.where(f => f.name != "yourfilename 1")
.tasks.where(t => !t.completed))
```
  1. exclude multiple files
```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))
```
6 Likes

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.

3 Likes

Thanks to @mnvwvnm and @obsidian337.

Some questions to @mnvwvnm, if I may:

  1. Why does your code for multiple files use paired ampersands? One ampersand seems to work okay. Better to use pairs?

  2. 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

1 Like

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 :slight_smile: (not from any skill for code or similar).
What I know?

  • “&&” is the logical AND operator; “||” is the logical OR operator; “!” is the logical NOT operator;
  • About “&” vs “&&”, don’t ask me why but it seems the “&&” is the most advised. The difference between & and && operators – The Blog of Colin Mackay
  • About “and” and “&&”, the issue isn’t about files vs folders. In plugin documentation says that 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 “&&”.
2 Likes

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

1 Like

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