How to get sum of all multiplyed values?

Hi! I have two fields with numbers in tiddlers with tag $:/Note

so I can multiply this fields
<$list filter="[is[current]tagging[]tag[$:/Note]] "> {{{[{!!nparametr-ВЕС кг}multiply{!!price}]}}}</$list>
and I get
276 847 12.66 176 2288 215 180 561 418 638 900 480 295 330 2040 176 1300 168 72 60 504 658
how can I get sum of all these values?
276+847+12.66+176+2288…

I think that is the purpose of the “reduce” filter.

Try adding :reduce[add<accumulator>] as a filter run. I think that should collapse all your outputs from the first run into a sum of everything.

/Mike

There is no first filter run, there are n filters in a list widget. That’s the difficult part.

This is the key feature we need for this:

Within the filter runs prefixed with :reduce , :sort , :map and :filter , the “currentTiddler” variable is set to the title of the tiddler being processed.

And this is the filter:

[all[current]tagging[]tag[$:/Note]]  :map[{!!nparametr-ВЕС кг}multiply{!!price}] +[sum[]]

Try this:

Instead of using a $list widget, write:

<$text text={{{ [<currentTiddler>tagging[]tag[$:/Note]] :map[{!!nparametr-ВЕС кг}multiply{!!price}] +[sum[]] }}}/>

Notes:

  • The first filter run gets the titles of all the notes associated with the current tiddler
  • The second filter run (:map[...]) replaces those titles with the desired calculation (based on the price)
  • The third filter run sums all the calculated values to give the final result
1 Like

I am not able to understand how it works
I make new tiddler in https://tiddlywiki.com/ and write

{{{[tag[shopping]get[price]multiply{!!quantity}]}}}

so I get 0 0 0 0

but it must work? https://tiddlywiki.com/#reduce%20Operator%20(Examples)

Thank you it works good
here is mwiktowy variant

<$set name="add-price" value="[get[price]multiply{!!nparametr-ВЕС кг}add<accumulator>]">
{{{[is[current]tagging[]tag[$:/Note]reduce<add-price>]}}}
</$set>