Add value of two fields and produce grand totals

Every tiddler tagged ‘class’ has two fields ‘boys’ and ‘girls’ holding the number of boys and girls respectively in each class. The title holds the class name X-A, X-B, etc. The body (text) carries some description of the class.

<$list filter="[tag[class]]">
<$link>
<$view field="boys"/>
<$view field="girls"/><br>
</$list>

produces a list giving number of boys and girls in each class.

Can I also add a total?

I looked up the sum[] filter operator. And tried:

<$text text={{{ =<currentTiddler>get[boys]] =<currentTiddler>get[girls]] +sum[] }}}/>

But that does not work. May be, some syntax error.

Also, will it be possible to get a grand total? Total number of boys, total number of girls and total number of students and total number of classes?

How can I get these totals in the output?

You are missing some square brackets.

Try this:
<$text text={{{ =[<currentTiddler>get[boys]] =[<currentTiddler>get[girls]] +[sum[]] }}}/>

Note: since you are getting field value from the current tiddler, you could simplify your filter to use field references instead of the get[fieldname] operator, like this:

<$text text={{{ =[{!!boys}] =[{!!girls}] +[sum[]] }}}/>

-e

4 Likes