Hi @svalais,
Sorry for the late reply, but your question is a bit more complicated as what to I’ve said in the previous post.
But here it goes (it’s not based on your code, for the reason it’s better to explain it):
{% assign last_year = period.minus_1y.custom.reserves %}
{% assign $0 = 0 %}{% assign $1 = 0 %}
{% stripnewlines %}
{% newline %}
| Column A | Column B | Column C | Column D |
{% newline %}
|---------------------|-------------25%-----------|-----------25%---------|---------25%------------+
{% fori res in period.custom.reserves %}
{% capture col_b %}amount_b_{{ forloop.index0 }}{% endcapture %}
{% newline %}
| {% input res.omschr %}
{% for res in last_year %}
{% if res[col_b] != 0 %}
last year: {{ res[col_b] | currency }}
{% endif %}
{% endfor %}
| {% $0+input res[col_b] as:currency %}
| **{{ $0+$1 | currency }}**
{% endfori %}
We create a collection, and it’s important to attach the collection to the period-drop, because that way we can call items from that collection from last year.
period.custom.reserves
Create the collection for items of last year :
{% assign last_year = period.minus_1y.custom.reserves %}
We are going to fill that collection with an item. The thing is, that we need to index those items as well (so the results of the current collection are linked to the same items from last year, which is a different collection).
Normally, you can do this by adding [forloop.index0] but in a collection you can’t go any further than 2 levels deep (unfortunately).
So, to fix that, we’ll capture it in our fori-loop:
{% capture col_b %}amount_b_{{ forloop.index0 }}{% endcapture %}
So, for each iteration of a loop, we’ll get the result of [col_b] as: amount_b_0 (first loop), amount_b_1 (second loop), and so on…
We’ll create that item in our collection period.custom.reserves :
{% $0+input res[col_b] as:currency %}
Now, the next year I want those results as well (which were inputted last year), and those values are in our collection last_year.
With a forloop in our fori-loop, we’ll need to get those items (with the same index of course):
{% for res in last_year %}
{% if res[col_b] != 0 %}
last year: {{ res[col_b] | currency }}
{% endif %}
{% endfor %}
This is the way to call for items in a collection from a previous period.
If you need items from a previous period not in a collection, the first post is a way to do it (and less complicated though).
Hope this helps you further; let me know if something is unclear.