Inline Query to display number of items

What I’m trying to do

I have a query that returns my reading log as a dataview table and I’d like to put the number of books read each year in the header that precedes the query.
The query looks like this:

	"![|60](" + cover + ")" as Cover,
	link(, title) as Title,
	author as Author,
	join(list(publisher, publish)) as Publisher,
	genre as Genre,
	finished as When
FROM #📚Book
WHERE finished.year = 2024
SORT finished ASC

What I’m trying to do is having the query preceded by a header and the number of the books I’ve read like this:
#### Read in 2024: 'number'

Things I have tried

I think I should build a query using
FROM #📚Book WHERE finished.year = 2024 and something like "count items"
but I actually don’t know how… :slightly_smiling_face:
How can I get this result?

One alternative could be something like the following:

#### Read in 2024: `$= dv.pages("#📚Book").where(p => p.finished?.year == 2024).length`

Update: Added the p.finished?.year so that it doesn’t fail if the finished field is not present.

Thanks holy, for the second (and maybe third or fourth time) for your help!
I got an error message: TypeError: Cannot read properties of null (reading 'year'). I guess it depends on the ‘type’ of data we’re dealing with: in property the field “finished” is a date field, maybe that’s the issue?
But… it’s strange because the dataview table has no errors. I mean:
WHERE finished.year = 2024 returns all books that have a date that contains “2024”.
For example that is the relevant property (in source mode) of a book I finished this year:
finished: 2024-01-01

What’s wrong?
Thanks again

The javascript variants are in general slightly more picky than the ordinary queries, so if a note is missing a given field it complaints a little.

Try either of the following:

p => p.finished?.year
p => p.finished && p.finished.year

Both of these should work, so it shouldn’t matter whichever you use.

Thank you @holroy !

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