How to get an inline sum of values with dataview?

I’ve searched documentation, forum, discord and on internet generally and can’t find a similar query anywhere.

I have a bunch of notes in a folder. Each note can have one (or none) inline value somewhere, like so: [variable:: 3]
The value is always a positive integer.

I’d like to sum up those values with an inline dataview query.
So far I’ve managed to get a comma separated list of those values with: $=dv.pages("folder").variable

It seems that adding them all up to get one number should be easy. There is a sum() function in dataview documentation, but that seems to work only in non-js queries. Or I just don’t know how to apply it here.

Any hints?

uhhh try sticking .reduce((a, b) => a + b, 0) on the end, see what you get!

Thanks for your reply. Unfortunately…

ah my mistake, try .values.reduce((a, b) => a + b, 0)

Worked like a charm. Thank you :blush:

1 Like

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