How to get the sum of fields of current tiddler [Solved]

I made: ```
fields[]sum[]

but it does not work

thanks.

Welcome

Fields[] returns a list of all fieldnames in the wiki, you cant sum names and it includes text and date fields.

Perhaps tell us more

Or try [all[current]get[fieldname]] etc

Yes, sorry, i have in the tiddler various fields: value1, value2, value3, …

I want to sum all of them, those starting with “value”.

I know I have to filter with a regexp but i don’t know how.

Try this:

[<currentTiddler>fields[]prefix[value]] :map[<..currentTiddler>get<currentTiddler>] :and[sum[]]

The first run returns all the field names that start with value for that tiddler.
The second run maps each field name to its value in that tiddler.
The last run sums them all.

Edit: Or you can use :reduce
[<currentTiddler>fields[]prefix[value]] :reduce[<..currentTiddler>get<currentTiddler>add<accumulator>]

3 Likes

Oh. I try the first one and irt works!

a lot of thanks to both!