How to get the number of items in a dataview query

First, search the help docs and this forum. Maybe your question has been answered! The debugging steps can help, too. Still stuck? Delete this line and proceed.

What I’m trying to do

I’m trying to create a Dataview query which gives me the average rating of the episodes of a series. I mostly achieved this:

I used the following code for this result:

const amounts = await dv.query(`
FROM #CheatSkillAndUnrivaledInTheRealWorldToo & #episode  
SORT rating desc

if ( amounts.successful ) {
	const sum = amounts.value.values
		.reduce((tmp, curr) => tmp + curr[1], 0)

	dv.table(amounts.value.headers, amounts.value.values)
	dv.paragraph("average: " + (sum/6))
}   else 
	dv.paragraph("~~~~\n" + amounts.error + "\n~~~~")

At the moment I have to manually type in how many episodes I have for the series so it can be calculated correctly.
I can see that dataview knows the number of results in a query, as it already displays it in the top left. Is there a way to give this number to my query, so it can automatically divide by the right amount?

Things I have tried

Honestly not much, as I have no idea where to begin. I have looked up similar problems to this one, but as I’m not really confident with coding I couldn’t apply those solutions to my case.

Any help is appreciated!

You mean like amount.value.values.length ?

1 Like

Yes, that worked!

Thank You!

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