Hi everyone, first days for me using this fantastic tool!
I found this great query that helps me sort my Projects by priority (which is a page property) and count all the uncompleted tasks inside of them.
table type as Type, priority as Priority, length(filter(file.tasks, (t) => !t.completed)) AS "Uncompleted"
from "Projects"
WHERE file.tasks AND length(file.tasks) > 0 AND length(filter(file.tasks, (t) => !t.completed)) > 0
sort priority desc
It would be similar to the other counts where you use a combination of length and filter, where you change the new filter expression to match your new criteria.
Thanks for the answer holroy.
Unfortunately not, currently i’m trying this but it doesn’t work
table type as Type, priority as Priority, length(filter(file.tasks, (t) =>t.text.includes("🔺"))) AS "High Priority"
from "Projects"
WHERE file.tasks AND length(file.tasks) > 0 AND length(filter(file.tasks, (t) => !t.completed)) > 0
sort priority desc
The correct way to check for a text having something else within in an ordinary query is to use contains(). The .includes would have worked in dataviewjs and javascript in general for strings (and some arrays), but you’re writing a DQL query and there you need to use contains().
So with a little rewrite (for display purposes) and using that function, and adding the other category the query looks like:
```dataview
TABLE type as Type
, priority as Priority
, length(file.tasks) as "\#"
, length(filter( file.tasks,
(t) => contains(t.text, "🔺") or
contains(t.text, "⏫")
)) AS "High #"
FROM "Projects"
WHERE file.tasks
AND length(file.tasks) > 0
AND length(filter(file.tasks, (t) => !t.completed)) > 0
sort priority desc
```
And this seems to do the trick reporting the correct number of tasks and high priority tasks, at least in my simple test setup.
Update: Corrected the query to use FROM "Projects"