# Making totals with registers

**URL:** <https://community.silverfin.com/t/making-totals-with-registers/552>\
**Category:** Templates\
**Tags:** math, register\
**Created:** [December 21, 2017, 2:05pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552 "2017-12-21T14:05:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cedric](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Cedric](https://community.silverfin.com/u/Cedric)\
**Post date:** [December 21, 2017, 2:05pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/1 "2017-12-21T14:05:57Z")

</div>

I’m trying to put a total in the first row of a table, the following rows the data needs to be put in.  
But it seems like it isn’t possible, am I right?

I used following code.

````auto
{{header}}{% newline %}
|Voorafbetaling aangever||| {{ $10 | currency }}{% newline %}
||Eerste voorafbetaling|{% input custom.vooraf1.datum as:date %}|{% $10+input custom.vooraf1.bedrag as:currency %}{% newline %}
||Tweede voorafbetaling|{% input custom.vooraf2.datum as:date %}|{% $10+input custom.vooraf2.bedrag as:currency %}{% newline %}
||Derde voorafbetaling|{% input custom.vooraf3.datum as:date %}|{% $10+input custom.vooraf3.bedrag as:currency %}{% newline %}
||Vierde voorafbetaling|{% input custom.vooraf4.datum as:date %}|{% $10+input custom.vooraf4.bedrag as:currency %}{% newline %}
{% endstripnewlines %}```
````

---

<div class="post-metadata">

**Author:** ![SamVanEenoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/samvaneenoo/32/134_2.png) [@SamVanEenoo](https://community.silverfin.com/u/SamVanEenoo)\
**Post date:** [December 21, 2017, 2:32pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/2 "2017-12-21T14:32:02Z")

</div>

Unfortunately this is impossible with registers, since they are read from the top to the bottom. You can solve this by doing the following:

> {% assign totaal = custom.vooraf1.bedrag+custom.vooraf2.bedrag+custom.vooraf3.bedrag+custom.vooraf4.bedrag %}
> 
> {% stripnewlines %}  
> {{header}}{% newline %}  
> |Voorafbetaling aangever||| {{ totaal | currency }}{% newline %}  
> ||Eerste voorafbetaling|{% input custom.vooraf1.datum as:date %}|{% input custom.vooraf1.bedrag as:currency %}{% newline %}  
> ||Tweede voorafbetaling|{% input custom.vooraf2.datum as:date %}|{% input custom.vooraf2.bedrag as:currency %}{% newline %}  
> ||Derde voorafbetaling|{% input custom.vooraf3.datum as:date %}|{% input custom.vooraf3.bedrag as:currency %}{% newline %}  
> ||Vierde voorafbetaling|{% input custom.vooraf4.datum as:date %}|{% input custom.vooraf4.bedrag as:currency %}{% newline %}  
> {% endstripnewlines %}

---

<div class="post-metadata">

**Author:** ![Cedric](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Cedric](https://community.silverfin.com/u/Cedric)\
**Post date:** [December 21, 2017, 2:37pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/3 "2017-12-21T14:37:30Z")

</div>

Thanks @Sam.

Any idea how I can solve it with this code?  
Here I made a fori loop (as I asked earlier today). In every loop, I want the total of only this loop, but I also want to make an overall total that needs to be put in the first row of the table…

````auto
{{ header }}
|Kinderopvang||| {{ $0 | currency }}

{{ header }}
{% stripnewlines %}{% fori kinderopvang in custom.kinderopvang %}
||{% input kinderopvang.naam %}|
{% newline %}
||Aantal dagen|{% $1+input kinderopvang.dagen %}||
{% newline %}
||Bedrag per dag|{% $2+input kinderopvang.bedragperdag as:currency %}||
{% newline %}
||Bedrag beperkt|{% $3+input kinderopvang.bedragbeperkt default:"11,20" as:currency %}||
{% newline %}
||Totaal aftrekbaar|{% if $2 > $3 %} {% $0+ $1*$3 as:currency %} {% else %} {% $0+ $2*$3 as:currency %}{% endif %} {{ $0 }}
{% newline %}{% endfori %}
{% endstripnewlines %}```
````

---

<div class="post-metadata">

**Author:** ![SamVanEenoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/samvaneenoo/32/134_2.png) [@SamVanEenoo](https://community.silverfin.com/u/SamVanEenoo)\
**Post date:** [December 21, 2017, 2:50pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/4 "2017-12-21T14:50:06Z")

</div>

@Cedric, this is a bit more complex. You need to use a forloop for a every value you have saved. Something like this should work.

> {% stripnewlines %}  
> {% for kinderopvang in custom.kinderopvang %}  
> {% assign bedrag = kinderopvang.bedragperdag %}  
> {% assign grens = kinderopvang.bedragbeperkt %}  
> {% assign dagen = kinderopvang.dagen %}  
> {% if bedrag \> grens %}  
> &nbsp;&nbsp;&nbsp;{% assign totaal = totaal+(dagen \* grens) %}  
> {% else %}  
> &nbsp;&nbsp;&nbsp;&nbsp;{% assign totaal = totaal+(dagen \* bedrag) %}  
> {% endfor %}
> 
> |Kinderopvang||| {{ totaal | currency }}
> 
> {{ header }}  
> {% stripnewlines %}{% fori kinderopvang in custom.kinderopvang %}  
> ||{% input kinderopvang.naam %}|  
> {% newline %}  
> ||Aantal dagen|{% $1+input kinderopvang.dagen %}||  
> {% newline %}  
> ||Bedrag per dag|{% $2+input kinderopvang.bedragperdag as:currency %}||  
> {% newline %}  
> ||Bedrag beperkt|{% $3+input kinderopvang.bedragbeperkt default:“11,20” as:currency %}||  
> {% newline %}  
> ||Totaal aftrekbaar|{% if $2 \> $3 %} {% $0+ $1\*$3 as:currency %} {% else %} {% $0+ $2\*$3 as:currency %}{% endif %} {{ $0 }}  
> {% newline %}{% endfori %}  
> {% endstripnewlines %}

---

<div class="post-metadata">

**Author:** ![Cedric](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Cedric](https://community.silverfin.com/u/Cedric)\
**Post date:** [December 21, 2017, 3:37pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/5 "2017-12-21T15:37:05Z")

</div>

@Sam

Changed it like this now. The overall total is not calculated and the second total in the loop isn’t correct. I tried to solve it myself but I couldn’t find the problem.

````auto
{% stripnewlines %}
{% for kinderopvang in custom.kinderopvang %}
{% assign bedrag = kinderopvang.bedragperdag %}
{% assign grens = kinderopvang.bedragbeperkt %}
{% assign dagen = kinderopvang.dagen %}
{% if bedrag > grens %}
   {% assign totaal = totaal+(dagen * grens) %}
{% else %}
    {% assign totaal = totaal+(dagen * bedrag) %}
{% endif %}
{% endfor %}
{% endstripnewlines %}

{{ header }}
|Kinderopvang||| {{ totaal | currency }}

{{ header }}
{% stripnewlines %}{% fori kinderopvang in custom.kinderopvang %}
||{% input kinderopvang.naam %}|
{% newline %}
||Aantal dagen|{% $1+input kinderopvang.dagen %}||
{% newline %}
||Bedrag per dag|{% $2+input kinderopvang.bedragperdag as:currency %}||
{% newline %}
||Bedrag beperkt|{% $3+input kinderopvang.bedragbeperkt default:“11,20” as:currency %}||
{% newline %}
||Totaal aftrekbaar|{% if $2 > $3 %} {% $0+ $1*$3 as:currency %} {% else %} {% $0+ $1*$3 as:currency %}{% endif %} {{ $0 }}
{% newline %}{% endfori %}
{% endstripnewlines %}```

 ![image|690x234](upload://5CFxlmZq95Uo7OwwqGH9Nu2rwAU.png)
````

---

<div class="post-metadata">

**Author:** ![Cedric](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Cedric](https://community.silverfin.com/u/Cedric)\
**Post date:** [December 21, 2017, 3:37pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/6 "2017-12-21T15:37:33Z")

</div>

Did something wrong with the picture, hereby

 ![image](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/1X/2769e99926eb1a407a43be9661cc690a89cf64b8.png)

---

<div class="post-metadata">

**Author:** ![SamVanEenoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/samvaneenoo/32/134_2.png) [@SamVanEenoo](https://community.silverfin.com/u/SamVanEenoo)\
**Post date:** [December 21, 2017, 3:47pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/7 "2017-12-21T15:47:30Z")

</div>

> {% if bedrag \> grens %}  
> {% assign totaal = totaal+(dagen \* grens) %}  
> {% else %}  
> {% assign totaal = totaal+(dagen \* bedrag) %}  
> {% endif %}

remove the spaces beteween dagen and grens and the spaces between dagen and bedrag

---

<div class="post-metadata">

**Author:** ![Cedric](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Cedric](https://community.silverfin.com/u/Cedric)\
**Post date:** [December 21, 2017, 3:52pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/8 "2017-12-21T15:52:34Z")

</div>

Great!

And how can I solve the part of the total of every loop? Next to “Totaal aftrekbaar”?

````auto
{% stripnewlines %}{% fori kinderopvang in custom.kinderopvang %}
||{% input kinderopvang.naam %}|
{% newline %}
||Aantal dagen|{% $1+input kinderopvang.dagen %}||
{% newline %}
||Bedrag per dag|{% $2+input kinderopvang.bedragperdag as:currency %}||
{% newline %}
||Bedrag beperkt|{% $3+input kinderopvang.bedragbeperkt default:“11,20” as:currency %}||
{% newline %}
||Totaal aftrekbaar|{% if $2 > $3 %} {% $0+ $1*$3 as:currency %} {% else %} {% $0+ $1*$2 as:currency %}{% endif %} {{ $0 }} {% assign $0 = 0 %}
{% newline %}{% endfori %}
{% endstripnewlines %}{% endifi %}```
````

---

<div class="post-metadata">

**Author:** ![SamVanEenoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/samvaneenoo/32/134_2.png) [@SamVanEenoo](https://community.silverfin.com/u/SamVanEenoo)\
**Post date:** [December 21, 2017, 3:56pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/9 "2017-12-21T15:56:46Z")

</div>

You need to reset all of your registers (like you did with $0).

---

<div class="post-metadata">

**Author:** ![Cedric](https://avatars.discourse-cdn.com/v4/letter/c/ecd19e/32.png) [@Cedric](https://community.silverfin.com/u/Cedric)\
**Post date:** [December 21, 2017, 3:59pm UTC](https://community.silverfin.com/t/making-totals-with-registers/552/10 "2017-12-21T15:59:26Z")

</div>

Hehe, should’ve seen it. 🤤  
Thanks.
