# Sub totals per Year

**URL:** <https://community.silverfin.com/t/sub-totals-per-year/1002>\
**Category:** Templates\
**Tags:** customized\
**Created:** [June 18, 2018, 11:29am UTC](https://community.silverfin.com/t/sub-totals-per-year/1002 "2018-06-18T11:29:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julie\_Vandekerckhove](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/julie_vandekerckhove/32/1071_2.png) [@Julie\_Vandekerckhove](https://community.silverfin.com/u/Julie_Vandekerckhove)\
**Post date:** [June 18, 2018, 11:29am UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/1 "2018-06-18T11:29:51Z")

</div>

Hi there

I’m making a overview of all the investments based on the details given in the template “Depreciation and investment table”.  
Now I only need to output the totals per year.

So if there are 3 investments in 2011 they need to sum of those details.  
The code already sums up the first year in the details but the following details output 0. So I made a mistake but I can’t seem to find where.

extract from the code:

```
_Installaties_{% assign current_account = #230000 %} 

  {% addnewinputs %}
  {% assign details = current_account.details | sort:'date' %}
{% endaddnewinputs %}

{% assign eerstejaar = "" %}
{% assign testjaar = "" %}

{% fori detail in details %} {% if forloop.first %}{% assign eerstejaar = detail.date |date:'%Y' %}{% endif %} {% assign testjaar = detail.date| date:'%Y' %}

{% if testjaar == eerstejaar %}{%$4+ detail.value%} {%else%} {{eerstejaar}} {{$4}} {% assign eerstejaar = testjaar%} {% assign $4 = 0 %}{% endif %}

{% endfori %} 

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [June 19, 2018, 8:01am UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/2 "2018-06-19T08:01:04Z")

</div>

Hello @Julie_Vandekerckhove,

I would do it like this (based on what we use as well in the standard template to create the details):

```auto
    _Installaties_{% assign current_account = #230000 %} 

    {% addnewinputs %}
      {% assign details = current_account.details | sort:'date' %}
    {% endaddnewinputs %}

    {% for detail in details %}
      {% comment %}when date is input, we can create the book year it belongs to{% endcomment %}
      {% if detail.date == blank %}
        {% assign new_year = "" %}
          {% else %}
        {% assign new_year = company.periods[detail.date].year_end_date | date:'%Y' %}
      {% endif %}
      
      {% comment %}display the total of each book year only when the last detail is given of each book year{% endcomment %}
      {% if current_year != blank and current_year != new_year %}
      **Totaal {{ current_year }}** _{{ $4 | currency }}_
        {% assign current_year = new_year %}
        {% comment %}at the end of each book year, we will need to reset the register $4{% endcomment %}
        {% assign $4 = 0 %}    
      {% endif %}    
      {% if current_year == blank %}
        {% assign current_year = new_year %}
      {% endif %}

    {% $4+ detail.value %}
    {% endfor %}

```

I added extra comment-tags where I think explanation is needed. Let me know if this is not what you’re looking for.  
If it is, let me know as well so this topic can be marked as a solution 🙂

---

<div class="post-metadata">

**Author:** ![Julie\_Vandekerckhove](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/julie_vandekerckhove/32/1071_2.png) [@Julie\_Vandekerckhove](https://community.silverfin.com/u/Julie_Vandekerckhove)\
**Post date:** [June 19, 2018, 11:41am UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/3 "2018-06-19T11:41:30Z")

</div>

> [@sven](#):
>
> % for detail in details %} {% comment %}when date is input, we can create the book year it belongs to{% endcomment %} {% if detail.date == blank %} {% assign new\_year = “” %} {% else %} {% assign new\_year = company.periods[detail.date].year\_end\_date | date:‘%Y’ %} {% endif %} {% comment %}display the total of each book year only when the last detail is given of each book year{% endcomment %} {% if current\_year != blank and current\_year != new\_year %} **Totaal {{ current\_year }}** _{{ $4 | currency }}_ {% assign current\_year = new\_year %} {% comment %}at the end of each book year, we will need to reset the register $4{% endcomment %} {% assign $4 = 0 %} {% endif %} {% if current\_year == blank %} {% assign current\_year = new\_year %} {% endif %} {% $4+ detail.value %} {% endfor %}

Yes this works! Thank you very very much!  
Just one issue remains, the first line always displays a 0 for the year and a 0 for the detail.value;

But thank you for this already.

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [June 19, 2018, 11:48am UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/4 "2018-06-19T11:48:39Z")

</div>

I can’t seem to reproduce that @Julie_Vandekerckhove.

Could you add a screenshot of your details? Because basically, that all we do - recreate the template Investements.

---

<div class="post-metadata">

**Author:** ![Julie\_Vandekerckhove](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/julie_vandekerckhove/32/1071_2.png) [@Julie\_Vandekerckhove](https://community.silverfin.com/u/Julie_Vandekerckhove)\
**Post date:** [June 19, 2018, 12:21pm UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/5 "2018-06-19T12:21:41Z")

</div>

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

so in the “plain code” you can not see the 0 but in the table above (about the same coding) I always have a 0 line.

> ```
> _Installaties_{% assign current_account = #230000 %} 
> 
> {% addnewinputs %}
> {% assign details = current_account.details | sort:'date' %}
> {% endaddnewinputs %}
> 
> {% fori detail in details %}
> {% if forloop.first %} {% assign $4 = 0 %} 
> |Jaar|vorig bj |a/b |boekjaar|Waarde|D/L|%|Vorige boekj|Boekj|Balans|BW|
> |----|---------|----|--------|------|:--:|:--|--------:|-----|------|-----:+{% endif %} 
> {% stripnewlines %}{% comment %}when date is input, we can create the book year it belongs to{% endcomment %}
> {% if detail.date == blank %}
> {% assign new_year = "" %}
> {% else %}
> {% assign new_year = company.periods[detail.date].year_end_date | date:'%Y' %}
> {% endif %}
> {% comment %}display the total of each book year only when the last detail is given of each book year{% endcomment %}
> {% if current_year != blank and current_year != new_year and current_year != blank %}
> |{{ current_year }}
> |{{ $4 | currency }}
> |a
> |aanschaf
> |bal & aan 
> |{{"L/D"}}
> |{{"5"}} 
> |afschr
> |afschr nu
> |tot af
> |boekw{% assign current_year = new_year %}
> {% comment %}at the end of each book year, we will need to reset the register $4{% endcomment %}
> {% assign $4 = 0 %}    
> {% endif %}    
> {% if current_year == blank %}
> {% assign current_year = new_year %}
> {% endif %}
> {% $4+ detail.value %}
> {% endstripnewlines %} {% endfori %}
> 
> Code community:
> 
> {% for detail in details %}
> {% comment %}when date is input, we can create the book year it belongs to{% endcomment %}
> {% if detail.date == blank %}
> {% assign new_year = "" %}
> {% else %}
> {% assign new_year = company.periods[detail.date].year_end_date | date:'%Y' %}
> {% endif %}
>   
> {% comment %}display the total of each book year only when the last detail is given of each book year{% endcomment %}
> {% if current_year != blank and current_year != new_year and current_year != blank %}
> **Totaal {{ current_year }}** _{{ $4 | currency }}_
> {% assign current_year = new_year %}
> {% comment %}at the end of each book year, we will need to reset the register $4{% endcomment %}
> {% assign $4 = 0 %}    
> {% endif %}    
> {% if current_year == blank %}
> {% assign current_year = new_year %}
> {% endif %}
> 
> {% $4+ detail.value %}
> {% endfor %}
> 
> ```

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [June 19, 2018, 12:26pm UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/6 "2018-06-19T12:26:16Z")

</div>

Could you show me the details of account #230000 I mean? @Julie_Vandekerckhove

I have this:

 ![56](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/1X/3e97e960503446d21a8881a3e29198343d8bb951.png)

which results in this:

 ![19](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/1X/49164d99f645981c99904aa18121fefa2ad427d1.png)

with your code. So it should be something different in your original details I presume…

---

<div class="post-metadata">

**Author:** ![Julie\_Vandekerckhove](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/julie_vandekerckhove/32/1071_2.png) [@Julie\_Vandekerckhove](https://community.silverfin.com/u/Julie_Vandekerckhove)\
**Post date:** [June 19, 2018, 12:27pm UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/7 "2018-06-19T12:27:25Z")

</div>

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

those are the start details

---

<div class="post-metadata">

**Author:** ![Julie\_Vandekerckhove](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/julie_vandekerckhove/32/1071_2.png) [@Julie\_Vandekerckhove](https://community.silverfin.com/u/Julie_Vandekerckhove)\
**Post date:** [June 19, 2018, 12:30pm UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/8 "2018-06-19T12:30:03Z")

</div>

I found my mistake, there is more code in the text than I showed you and some of the variables you used were already being used and assigned so I started with the wrong content.

I’m sorry.

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [June 19, 2018, 12:30pm UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/9 "2018-06-19T12:30:43Z")

</div>

No problem at all, case closed after all 😉

---

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [June 19, 2018, 12:30pm UTC](https://community.silverfin.com/t/sub-totals-per-year/1002/10 "2018-06-19T12:30:46Z")

</div>


