How to query for a field and also adding all the tasks under heading

What I’m trying to do

I am trying to query all my tasks under the heading To-Dos AND also the completed tasks from today. My approach is the following.

I have a task under a heading:

## To-Do
- [x] jkladjf [completion:: 2024-06-01]`

Now I want to query for

  1. all the tasks under the heading “To-Do” AND are not completed
  2. all the tasks under the heading “To-Do” AND the field “completion” with the value “2024-06-02” AND are completed
    This way I can see all uncompleted tasks AND all tasks which I maybe have accidentally clicked (for this day)
```dataview
task
FROM "1 - Daily"
WHERE econtains("To-Do", meta(header).subpath) AND !completed
WHERE econtains("To-Do", meta(header).subpath) AND completion="2024-06-02" AND completed
```

Finally I want to put the following in my Daily Notes Template, so every time I open a new Daily Note it gets pasted with todays date.

```dataview
task
FROM "1 - Daily"
WHERE econtains("To-Do", meta(header).subpath) AND !completed
WHERE econtains("To-Do", meta(header).subpath) AND completion="{{date}}" AND completed
```

You’re quite close to your wanted reult, and it’s nice to see you’ve tried. There are two issues which might disturb your result, and the first is that when doing multiple WHERE clauses these are by default being AND’ed together, so you essentially get the failing combination of completed and not completed at the same time.

The second issue is that you’re comparing a date value against a string, which I don’t think will work, so it would be better to compare against an actual date. (Do know that in some cases Dataview might do this behind the scenes for you)

The last comment would be to slightly simplify your query since both variants require the heading, and in the second part if it’s not uncompleted it’ll be completed…

```dataview
TASK 
FROM "1 - Daily"
WHERE econtains(meta(header).subpath,  "To-Do") 
WHERE !completed OR  completion = date("2024-06-02")
```

Untested, but hopefully it should work.

1 Like

doing multiple WHERE clauses these are by default being AND ’ed together

Thanks for the info, I had no idea as you can see. Now it makes sense it didn’t work the way I tried.

The second issue is that you’re comparing a date value against a string, which I don’t think will work, so it would be better to compare against an actual date. (Do know that in some cases Dataview might do this behind the scenes for you)

Okay, I thought something like that might be the issue but I didn’t know how to implement the date() string. Now it makes total sense seeing it in your query.

Your query works perfectly! Thank you very much.

Btw my query was built on forum questions answered solely by you, thats why I got so close. All my projects are basically Frankenstein’s Monsters out of your answers in this forum.

image

1 Like

Hehe…