I have author pages in my vault, and I’m trying to add inline queries that will show me the number of pages I’ve read by that author, as well as the average rating for the books I’ve read by that author. I’ve been able to accomplish this using dataview tables, but the result is a single line that includes extra artifacts as a result of the table format. I would prefer to use inline queries to get a single number returned, but haven’t been able to get my queries to work (admittedly, I am not well versed in javascript).
What I’m trying to do
My book pages have these Obsidian properties (amongst others):
author
pages
rating
On my author page, I have 3 queries where I’m trying to return the following data points, along with the code I’m currently using:
- Pages Read (by author)
LIST "  " + sum(rows.pages)
WHERE pages AND author = [[Shari Lapena]]
GROUP BY Total
- Average Rating (by author)
LIST "  " + round(sum(rows.rating) / length(rows.rating), 2)
WHERE rating AND author = [[Shari Lapena]]
GROUP BY Total
- Total number of books read (by that author) note: I have an inline query for this and it works beautifully; no assistance needed with this one
$= dv.pages("#book").where(p => p.author?.path?.includes("Shari Lapena")).length
I’m nesting my queries within callouts, and this is what it looks like:
Things I have tried
I’ve done a lot of googling, and based on what I’ve found I have played around with versions of this to get the total number of pages read by the author:
$=dv.pages("#book").pages.where(p => p.author?.path?.includes("Shari Lapena")).values.reduce((a, b)=>a+b,0)
This code does not return an error, but the result is 0 and it should be 1310. I am also not sure how to modify this code to get an average rating; I have not found any inline queries that produce an average calculation.
I am not sure what else to try, at this point.
I appreciate any assistance.
