I believe so, its quite complex to explain, I may be off line, and I am definitely away from my desktop for the next day or so. Hopefully others can help.
Here is the basic approach.
Generate from a macro a list of all values, for all fields, for all tiddlers in a give filter. You need to make sure deduplication of titles (Ie the numbers) do not occur.
Wikify the result of the macro, then sum all the numbers.
Again make sure deduplication of titles (Ie the numbers) do not occur.
It is different, the subfilter operator does not have ‘title’ as a parameter it is run once. The new ‘invokestring’ filter takes ‘title’ as a parameter, and within it’s iterator substitutes the variable ‘$title$’ and runs this new filter. - it is run N times.
Similar to your “invokestring” filter example, the makesum() macro defines a filter run sequence that computes the sum of all fields starting with ct- for a single tiddler. However, instead of replacing a $title$ placeholder, we use <currentTiddler> and <..currentTiddler> (for the “inner” :map filter run)
Then, in the invoking filter, we get the list of all tiddlers tagged with tidsToSum and use :map[subfilter<makesum>] filter run prefix to apply the makesum filter to get a list of ct-* field totals for each tagged tiddler, and then add those results together using the last +[sum[]] filter run.
@EricShulman Thanks for the wikitext based solution you provided. I will have to test it out before commenting more. It works, but I have to make some modifications to suit my tiddler structure.
A small doubt how to modify the code to include fields with both ct- and cect- prefix. When I tested my code wasn’t working, must be due to some errors.
@EricShulman I want to multiply the numerical value derived from this filter {{{ [tag[Journal]month<currentTiddler>] :map[subfilter<ct-sum>] +[sum[]] }}} with another number (for example say 100), how to do that ?
However, I assume that you have defined three different subfilters (for ct-, usg-, and mri- field prefixes) because you want to also compute individual sums for each of those field prefixes.
If this is the case, then without adding the all-sum subfilter definition, you could write:
As discussed in this thread, I want to get the sum of all fields with a prefix ct- and cect- in a particular tiddler . I want to store this sum in a field called ct-sum of the same tiddler so that I can use this value in a dynamic table. I added this code
When I transclude the field ct-sum in the same tiddler like {{!!ct-sum}}, I am getting the sum value, but when I am using the field ct-sum in the shiraz dynamic table, the value is not seen (instead zero is seen)
(As a side note, I prefer to use spaces between the triple braces of the transclusion and the filter run square brackets—even though the spaces aren’t strictly necessary—because it makes it easier to spot missing or mismatched brackets.)
If that doesn’t solve the issue…
Without looking at your dynamic table code, I’d assume that there’s a list widget in play somewhere, and either it’s changing the value of <<currentTiddler>> to a different tiddler that doesn’t have the " ct-sum" field, or it’s setting and relying upon a different variable that your filter isn’t using (and thus, again, you’re trying to transclude the field from a tiddler that doesn’t have it).