How to calculate sum of fieldvalues when the tiddler list and fieldnames are stored as variables

I have defined some variables using let and list widgets for my dynamic table for creating a footer so as to display data like sum.

  1. tbl-filter is the variable that stores the list of the tiddlers in this filter run. Its stores value like [budget-month[2025-05]budget-type[transaction]]
  2. tbl-field-value is the variable that stores the name of the field. This stores fieldname like transaction-amount

Now I want to get sum using these variables. That is the sum of fieldvalues in the field transaction-amount or the tbl-field-value in the tiddlers [budget-month[2025-05]budget-type[transaction]] or the tbl-filter

How to create such a filter run ?

The below given code works

{{{ [budget-month[2025-05]budget-type[transaction]get[transaction-amount]] +[sum[]] }}}

Based on that how to create the code using the variable I mentioned above. Code which I tried is not working. I think there should be some sort of substitution

{{{ [<tbl-filter>get<tbl-field-value>] +[sum[]] }}}

Edit:
I tried this code also which also doesn’t work

{{{ [$(tbl-filter)$get[$(tbl-field-value)$]] +[sum[]] }}}

Try this:

{{{ [subfilter<tbl-filter>get<tbl-field-value>] +[sum[]] }}}

-e

1 Like
`$(tbl-filter-mod)$get[$(tbl-field-value)$]] +[sum[]]`

gives

[budget-month[2025-05]budget-type[transaction]get[transaction-amount]] +[sum[]]

But I need

{{{ [budget-month[2025-05]budget-type[transaction]get[transaction-amount]] +[sum[]] }}}

to get the result. Should I wikify it ? How to do that ?

That works @EricShulman . Thank you. In which all conditions should the subfilter operator be used ?

To simplify addition of the values found in a given field I have written a filter operator (with help from others including ChatGPT) that sums the value found in the fieldname of the titles given to it.

It seems to me that with accounting heavy tiddlywikis the provision of operators for basic maths that act on fieldnames would simplify such wikis quite a lot.

  • Of course now this can be done via custom operators.

Did you meant functions ?
A sample code will be useful to understand

I am having trouble finding my prior work, I will keep looking.

What I did was create a filteroperator (like the core JS operators), that accepted as a parameter a fieldname. You would then use a filter to feed it a list of titles and it simply summed the contents of the fieldname (accepting negatives).

eg addfield[fieldname] vs ...get[fieldnamet]] +[sum[]]

My point here is with a little effort it is possible to radicaly reduce the complexity by building finance specific operators.

  • I did this before functions/custom filter operators were available and they may be a way to build these simplified operators.

Consider perhaps if tiddlers had credit and debit fields, but were always positivly signed. I could imagin a balance operator eg;

balance{!!credit},{!!debit}

Where the parameters can be variables, fieldnames, literals and the balance is computed for all input tiddlers. Sum all credits, Sum All debits, subtract debits from credits.

  • Perhaps even a third parameter for an optional balance carried forward (Last balance)

[Edited] If we go to the effort of writting some operators for finance/accounting arguably it would default to approriate field names such as debit and credit so one would just use the balance[] operator without paramters.

1 Like