Query count and grouping

Hello everyone, I’m writing because I’m new to the world of SilverBullet and I haven’t understood how to perform a count on a query. Specifically, I log the start and end dates for each book I read; then, on a recap page, I’d like to count how many books I finished in a year.

In Obsidian, I used Dataview with the following query:

```dataview 
table length(rows) as count
Flatten row["End Date"] as d
where pgType = "book" AND d != null
group by d.year as year
sort year DESC

There’s no group by support yet, you can do counts on queries though, e.g.

```template
Total pages tagged with #person: {{count({page where tags = "person"})}}
```
3 Likes

Hi and thank you. I tried it out and it works, but I encountered a problem with the properties, specifically with spaces like End date. The error message is:

Error: Parse error in: count({page where tags = “book” and year(End date) = “2025”})

I’ve tried escaping the space with a backslash (End\ date), but it didn’t work. How can I fix this?

You can put backticks around fields with names: `End date`

1 Like

hey, is there any way to count query’s results in v2 ? I’m trying to count the time a specific task (with the same name) is done in several files
(to note presence at a class)

To get a count of all results of a query, just add a “hash sign” (#) in front of the query, like so:
${#query[[from index.tag "page"]]}

2 Likes

Ok, but if I wont to count all document that have the field “End date” between 2024-01-01 and 2024-12-31?

With silverbullet v1 I used this: {{count({page where tags = “book” and status = “Completed” and year(`End date`) = “2025”})}}.

How can reproduce in v2?