DataView Query for counting all completed tasks grouped by task

I have a list of tasks in my daily note that looks like this

  • Clean
  • Steam
  • Prayer
  • Exercise
  • Dishes

I am trying to write a dataview query that goes over all my daily notes and that shows the number of times I completed each task in the past week

I am able to make a dataview table showing all my tasks and the count using the below query

TABLE 
length(filter(tasks, (t) => t.checked)) AS "Count" 
FROM "4 Completed"
FLATTEN file.tasks as tasks
WHERE date(file.name)    // To look at my daily note which are named with a date 
AND date(file.name) >= (date(today) - dur(7 days)) // Look at last seven days
GROUP BY tasks.text AS "Tasks"

However, the count for all the tasks is zero, and I don’t understand why. Here is the current result from the above query

Tasks Count
Clean 0
Dishes 0
Exercise 0
Prayer 0
Steam 0

What I am hoping to achieve after the query is fixed

Tasks Count
Clean 3
Dishes 5
Exercise 3
Prayer 2
Steam 1

Can someone help me figure out what I am doing wrong here?

When you do a GROUP BY statement, all other properties are grouped under the rows object , and the key expression can be found in key. I also recommend changing the plurality of a field name when using FLATTEN to avoid confusion later on.

Using this two facts as guidelines we end up with:

```dataview 
TABLE 
length(filter(rows.task, (t) => t.checked)) AS "Count" 
FROM "4 Completed"
FLATTEN file.tasks as task
WHERE date(file.name)    // To look at my daily note which are named with a date 
AND date(file.name) >= (date(today) - dur(7 days)) // Look at last seven days
GROUP BY task.text AS "Tasks"
```

Query is untested, but it should work. I’ve not looked at other aspects of your query, like proper date handling.

Great. That worked. Thanks! This is the final query that I ended up using with tasks plugin

TABLE
length(filter(rows.task, (t) => t.checked)) AS "Count"
FROM "4 Completed"
FLATTEN file.tasks as task
WHERE date(file.name) 
AND date(file.name) >= (date(today) - dur(7 days)) 
GROUP BY split(task.text," ✅ ",1)[0] AS "Habit"

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