I am trying to write a Dataview Task query in DQL to generate a list tasks with either a scheduled date or a due date. However I have been unable to filter out tasks with no scheduled or due date.
Things I have tried
This is my query:
```dataview
TASK
FROM "010 DailyNotes" AND #task
WHERE
due <= date(today)
AND scheduled <= date(today)
AND !completed
AND contains(tags, "#task")
SORT file.name DESC
GROUP BY section
```
By way of explanation I should say that the individual tasks have been created using the Obsidian Task plugin and are prefixed with #task
I don’t use the Tasks plugin, but the following where statement works in my local test vault to show only those tasks that have a due OR scheduled flag set.
Yes, as you can see from my query script, I do have essentially that, but it is scooping into the query results undated tasks too. To help, below is a typical Obsidian Task item:
- [ ] #task This is a test task ⏳ 2023-03-17 📅 2023-03-18
Perhaps it is to do with having the Tasks plugin (which I don’t have) but the following works in local tests to only show uncompleted tasks with due or scheduled dates assigned. Note that the query uses OR, not AND. In your post you mention listing tasks with a scheduled OR due date, but in your query you use AND, so I am not sure which one you want. I suspect OR.
- [ ] #task 1 Test task ⏳ 2023-03-17 📅 2023-03-18
- [ ] #task 2 Test task with no dates
- [ ] #task 3 Third task ⏳ 2023-03-17
- [ ] #task 4 Fourth task 📅 2023-03-18
- [x] #task 5 Fifth completed 📅 2023-03-18
- [ ] #task 6 This has no dates
- [x] #task 7 Completed with no dates
# dateless tasks (2, 6, and 7) not shown
```dataview
TASK
FROM #task
WHERE
due
OR
scheduled
AND
!completed
SORT file.name DESC
GROUP BY section
```
Or still not what you want? I might well have misunderstood.
Thanks for your help eightning. I have now got the solution - see below:
```dataview
TASK
FROM "400 Project" AND #task
WHERE
contains(tags, "#task")
AND (due <= date(eom)
OR scheduled <= date(eom))
AND (date(due) != null
OR date(scheduled) != null)
AND !completed
SORT file.name DESC
GROUP BY section
```
I’m glad you found a working solution, I just wanted to point out some possible simplifications of your query:
```dataview
TASK
FROM "400 Project" AND #task
WHERE
contains(tags, "#task")
AND (
( date(due) AND due <= date(eom) ) OR
( date(scheduled) AND scheduled <= date(eom) )
)
AND !completed
SORT file.name DESC
GROUP BY section
```
What I’ve done here is to group the due and scheduled into their own context, and I’ve used indentation to hopefully make a clearer connection between the various parts. I’m also partial to having space around the parenthesis when grouping boolean expression, as I feel it helps the readability.
The net effect should be the same though, it’s just a different visualisation.
I’m not quite sure I follow what you want out of your new queries. Today but <30 days, what do you mean by that? For today you could use date(now). For time spans, you might want to look at some variation with durations, see dur()
For undated tasks, I reckon you could try some variations using !due or !scheduled or similar.