Help using the sum operator

71 views
Skip to first unread message

Reaktorblue

unread,
Apr 21, 2020, 1:41:46 PM4/21/20
to tiddl...@googlegroups.com
Hello,

I'm working on a project and had a few questions. I have several tiddlers listed as categories and tasks of that category.

For example, I may have:

  • tiddler title: Car Repair
  • tiddler tag: Category
  • tiddler title: Oil Change
  • tiddler tag: Car Repair
  • tiddler field: cost, value: 30.00
  • tiddler title: New Tires
  • tiddler tag: Car Repair
  • tiddler field: cost, value: 300.00
  • tiddler title: New Passenger Side Mirror
  • tiddler tag: Car Repair
  • tiddler field: cost, value: 60.00

1) I'm using the following to return $390.00 when viewing the "Car Repair" tab which indicates three tiddlers, "Oil Change", "New Tires", and "New Passenger Side Mirror"

Total Cost: $<$text text={{{ [tag<currentTab>get[cost]sum[]] }}}/>

The code works perfectly however, in another tiddler, I made a table to show me all the categories. Is it possible to change the code so the table indicates the sum of the cost field of all the tiddlers tagged with the title of the tiddler listed in that row? For example, my table should have a row indicating "Car Repair" as the tiddler title the next cell I would like to have should indicate the total sum of cost, from all the tiddlers tagged "Car Repair". I believe the following will work however, I was hoping to not explicitly assign it to "Car Repair" so that it will update for all rows that the table generates.

$<$text text={{{ [tag[Car Repair]get[cost]sum[]] }}}/>

2) Is it possible to use an ordered list when using the list-links-draggable macro instead of an unordered list or is it possible to use list-links-draggable with a table so that the table rows are draggable too?

Mark S.

unread,
Apr 21, 2020, 2:44:05 PM4/21/20
to TiddlyWiki
How are you building your table? It's possible to build it with nested lists, making the entirety automated. But I digress.

You probably want a macro

So at the top of your tiddler you might have this:

\define cost(expense) $<$text text={{{ [tag[$expense$]get[cost]sum[]] }}}/>

which can be invoked like this:

<<cost "Car Repair">>

and changed around for other costs by handing it a different parameter:

<<cost "Fuel">>

<<cost "Registration">

etc.

Reaktorblue

unread,
Apr 21, 2020, 3:00:35 PM4/21/20
to TiddlyWiki
I was able to answer my question using the below code.

$<$text text={{{ [tag{!!title}get[cost]sum[]] }}}/>

I do like the idea of trying that in a macro though. It looks like it could clean up some of the code if I did it via a macro. Are macro's available throughout the entire tiddlywiki or are they only available to the tiddler they're defined in?

Sadly, I still haven't found a nice way to use the draggable method to reorder task list items, such that I still have a checkbox and number associated with it but I'll keep looking otherwise. Thanks for the response, it's given me a bit to think about!

Mat

unread,
Apr 22, 2020, 2:08:36 AM4/22/20
to TiddlyWiki
Macros are easily created. You decide if you want it to be local or global. Local macros are put in the current tiddler whereas global ones are put in separate tiddlers tagged "$:/tags/Macro"

There's lot of documentation on macros on tiddlywiki.com

<:-)
Reply all
Reply to author
Forward
0 new messages