How to sum a data tiddler?

Can anyone point me to the relevant documentation on how to sum all the entries in a data tiddler and display the name + value?

I am trying to keep records from a renovation project in TW and would like to construct tables with items and cost of items plus the total. Data would be sitting in data tiddlers. An example of a data tiddler could be:

item1:50
item2:2500
labor:700

Is it better to use properties ?

Is TW event a good fit for this type of record keeping ?

Thank you.

2 Likes

Just a quick answer i think tiddlywiki is suitable and it is possible to do what you ask.

You just need a filter to extract the values you want and you can sum them with add. Within a filter the numbers will be concidered titles, you need to ensure no deduplication occurs, ie duplicates eg the same number twice is not reduced to one. See the = symbol.

I may give a fuller answer later today if no one else has.

A lot of beginners have the misapprehension that data tiddlers are the main structure for handling data. But data tiddlers are actually an after thought. If you look at the list of available filter operators for data tiddlers, there’s almost nothing – just 3 or four.

In Tiddlywiki, the main data structure is the tiddler, and there are dozens of filter operators to manage tiddlers.

So if you make 3 tiddlers:

item1
item2
labor

and give them each an expense field:

expense: 50
expense: 2500
expense: 700

Then you can sum them up just like this:

{{{ [has[expense]get[expense]sum[]] }}}

Any solution with data tiddlers will be somewhat more complicated. If your data tiddler is called ‘data’, then you can get the sum of all values like this:

<$vars sum-it="[add<accumulator>]">
{{{ [[data]indexes[]] :map[[data]getindex<currentTiddler>] +[reduce<sum-it>] }}}
</$vars>

So, not too bad, now that we have the map filter expression. But for the long term, I would still consider using tiddlers.

2 Likes

I have to try this to make sure it works, but wouldn’t it work?

{{{ [has:index[expense]getindex[expense]sum[]] }}}

EDIT: ARG, I misread the OP. All expenses in one data tiddler, that’s very different from what I was thinking (i.e. “expense” as a single data item for each of many data tiddlers.)

EDIT Deux: {{{ [[List of expenses]indexes[]] :map[[List of expenses]getindex<currentTiddler>] +[sum[]] }}}
Yeah, I enjoy this stuff a little too much …

Yup, sample attached. Download and drag into tiddlywiki.com to study/view imported tiddlers.SumExpenseValuesInDataTiddlers.json (678 Bytes)

EDIT: refer to my “ARG” just above …

I think data tiddlers are A-1 for all sorts of things.

And sure, TiddlyWiki is great for record keeping. Like all record keeping, regular backups are a really good idea.

Thank you, Charlie_Veniot and Mark S for suggestions.