Summing multiple field values

Hi,

I want to log various activities during the day and I was planning to use a field for each activity.

Let’s say the ‘run’ field is for duration of runs. I know I can sum the total time across tiddlers with this:

{{{ [tag[log]get[run]sum[]] }}}

But let’s say I go for 2 x 30 minute runs. Rather than entering 60 minutes for the day’s total, is there a format that would allow 30 & 30 to be entered in the same field to give the total but also showing the 2 events?

Regards
Jon

{{{ [tag[log]get[run]split[ ]sum[]] }}}

for e.g

run: 30 20 30

but also showing the 2 events?

What does that mean?

Ah, thanks Mat - I thought there was probably a way of doing it.

I just meant that the 2 entries would show that there had been 2 events.

At first your solution didn’t sum the contents of the fields from the other tiddlers until I found out that a space was required after the number entered into the field - without the space, the number wasn’t summed - if that makes sense.

Many thanks
Jon

(if there was only one entry)

You can count the entries like this, if that is what you mean:

{{{ [tag[log]get[run]split[ ]!is[blank]count[]] }}}

If 30 30 is written without a space it becomes 3030 so that doesn’t quite make sense for me… but as long as it works :grinning_face_with_smiling_eyes:

Hey, It’s late my end, but not that late!

I meant if some of the tiddlers only had a single entry eg. ‘5’, then that number wouldn’t be added with the others, unless a space was inserted after it - try it!

Last thing, how would I get the average instead of the sum? (tried replacing the word but doesn’t work)

Ta.

It seems to work as it should when I try it on https://tiddlywiki.com/prerelease/

Do note the space character in split[ ]

Average:

{{{ [tag[log]get[run]split[ ]average[]] }}}

Jon - here you are relying on split[ ] to divide entries but perhaps you should be using listops and enlist functionality instead.

Though personally this idea of multiple time entries (times in one field) is little additional information. I would encourage you to create a tiddler for each logged time, you can then provide start and end times, where you went, notes etc… or the intermediate a “data tiddler”. Tiddlers such as time log entries can otherwise be hidden. This would allow you to add more features as you proceed.

Thanks for that.

Well, that’s odd. I’ll try it on TW tomorrow but in my wiki, if I have 2 tiddlers with the number 5 & 10 in each respective field, without a space after the number, the total shows as zero and only shows 15 with the space after the digit.

Thanks again
Jon

Thanks Tones and I am generally getting into the better habit of using smaller units and not lumping things together, but in this case, I don’t need that level of detail - although I will give it some thought, just in case.
Regards
Jon

Prolly doable but a difficulty with enlist is that double entries are removed, AFAIK.

Can’t get that average to work - if I backspace ‘sum’ and replace with ‘average’ there’s no output…time for bed I think.

Create a demo on tiddlyhost and it will be much easier to help you.

1 Like

Only if not handled correctly.

Well, you’re right Mat, everything works as expected at https://tiddlywiki.com/

So, I upgraded my wiki expecting the same, but not so:

Split sum and count behave as they did before - the space after the number is required. So if there are 2 tiddlers with a single number in the field for each tiddler, split sum and count are zero unless there is a space after the number.

The average calculation is now recognised in my wiki (before there was no output) but it doesn’t include the total from multiple entries in a single field.

I’ve uploaded something here to show the calculations working as expected and with the screenshots from my wiki showing the difference there.

Presumably there must be something in my wiki which is responsible for the different behaviour - would be good to know what.

Thanks
Jon

Hi Jon,

In your wiki could you try this:
{{{ [tag[log]get[run]join[ ]split[ ]sum[]] }}}

Fred

Yes Fred,

That works!!

What’s the reason for that then?

Well I don’t really know why, but I thought that if it works when you add space, then the filter can add space by itself with join[ ].
I tested it in your online example and it didn’t break the working example, so why not! :man_shrugging:

Well, this doesn’t make much sense to me anyway!

Adapting your suggestion worked for the average as well but what’s weird is that the original average calculation also started working!! (the split sum remains unchanged)

I thought I’d seen this during testing but ignored it as there were too many variables to deal with, so there is definitely something intermittent at work with regard to the average calculation at least.

I’m pleased I’ve got something to work with now, but it would be good to know if there’s something lurking in my wiki which I need to exorcise!

Thanks again
Jon

By default, yes. But if you use the raw operator suffix it will not “dedupe”

See: https://tiddlywiki.com/#enlist%20Operator