How to sum YAML data only from a specific year?

Hi.
I’m trying to build my book library in Obsidian.
I have frontmatter on each book page that includes Pages_Read, Date_Read: yyyy-mm-dd, Rating

Now I’m trying to build a separate page with statistics (Dataview). I’d like to have a table with a row that displays how many pages I’ve read in each specific year, but no idea how to do sums correctly. I’ve trudged through loads of topics here in the forum, but nothing seems to work for my case specifically. Any idea how to do this?

If I try either this:

TABLE WITHOUT ID
	length(rows) as Count,
	sum(rows.pages_read)
FROM "Books"
WHERE date_read.year = 2023
GROUP BY true

or this

TABLE WITHOUT ID
	length(rows) as Count,
	sum(rows.pages_read)
FROM "Books"
WHERE date_read.year = 2023
GROUP BY true

This is what I end up with:

which clearly is incorrect.

The correct result would be the sum of values 380+320+187 (which are the number of pages of the three different books that I logged into the “Books” folder to test.

looks like strings being added together instead of numbers
try using number() inside the sum

https://blacksmithgu.github.io/obsidian-dataview/reference/functions/#numberstring

so like this:

TABLE WITHOUT ID
	length(rows) as Count,
	sum(number(rows.pages_read))
FROM "Books"
WHERE date_read.year = 2023
GROUP BY true 
1 Like

It worked! Thanks!

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