Sub totals per Year

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

Hello @Julie_Vandekerckhove,

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

    _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 :slightly_smiling_face:

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.

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.

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 %}

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

I have this:

which results in this:

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

those are the start details

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.

No problem at all, case closed after all :wink: