Count (un)checked checkbox

Hi,

I have a note with some checkboxes organized like this :

Note 1

a1
b1
c1

Note 2

a2
b2
c2

I want to count checked or unchecked checkboxes.

For that i use (for example for the unchecked boxes) :
length(this.file.task) - length(filter(this.file.tasks, (t) => t.completed)

Or
```dataview TABLE length(filter(file.tasks, (t) => !t.checked)) AS "Not done", length(filter(file.tasks, (t) => !t.checked)) + length(filter(file.tasks, (t) => t.checked)) AS "Done" FROM "Note" ```

But i would like to display separently “Note1” and “Note2” or either “Note1” or “Note2”.
I mean, if i have 2 unchecked checkboxes in Note1 and 1 in Note2, it will display “3 unchecked boxes”, but I don’t know how to consider only “note1” for example.

Someone know if it’s possible please?

I hope my request is clear enough.

Best

Stéphane

You could try something like:

```dataview
TABLE Unchecked, Completed
WHERE file.tasks
FLATTEN length(filter(file.tasks, (t) => t.completed)) as Completed
FLATTEN length(filter(file.tasks, (t) => t.status = " ")) as Unchecked
```

And that should give you the unchecked and completed count for any file having tasks defined.

If you want the same table just for the current file you could do:

```dataview
TABLE Unchecked, Completed
WHERE file = this.file
FLATTEN length(filter(file.tasks, (t) => t.completed)) as Completed
FLATTEN length(filter(file.tasks, (t) => t.status = " ")) as Unchecked
```
1 Like

Hi,
Thank you for your reply, but maybe i didn’t understand but your code (like mine) consider “note1” and “note2” together.
In my example, “note1” and “note2” are to different part in the same file. Actually, i would like to keep “note1” and “note2” in the same file but count only for the part called “note1” for example.

Sorry otherwise maybe i do mistake and i don’t know dedfine tasks or something lke this.

Best

Stéphane

So in essence you want to calculate stuff from a given note based on sections (and not on separate notes). That explains a few things. Try the following query then and see if that returns what you want:

```dataview
TABLE length(rows) as Count, completedCount, uncheckedCount
WHERE file = this.file
FLATTEN file.tasks as task
GROUP BY meta(task.section).subpath as Section

FLATTEN length(filter(rows, (r) => r.task.completed)) as completedCount
FLATTEn length(filter(rows, (r) => r.task.status = " ")) as uncheckedCount
```

Hi,
Thanks you very much, it works well !
Stéph

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