# CASE: display reconciliation of previous period

**URL:** <https://community.silverfin.com/t/case-display-reconciliation-of-previous-period/1197>\
**Category:** Cases\
**Tags:** drops, drop\_period, methods, use\_case\
**Created:** [September 17, 2018, 11:40am UTC](https://community.silverfin.com/t/case-display-reconciliation-of-previous-period/1197 "2018-09-17T11:40:12Z")\
**Posts on this page:** 1\
**Page:** 1

<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:** [September 17, 2018, 11:40am UTC](https://community.silverfin.com/t/case-display-reconciliation-of-previous-period/1197/1 "2018-09-17T11:40:12Z")

</div>

Let’s take this case:

> [@CASE: create fori and group on certain values](https://community.silverfin.com/t/case-create-fori-and-group-on-certain-values/1195):
>
> Let’s say we import a whole bunch of data through the automatic reconciliation function in a reconciliation template. To make it simple, I’ll import all parts of a car with their expenses from a certain excel-sheet I’ve gotten from my client, like this: [03] Because of all double types in the excel-sheet, I’d like to group these on type to see what amount correspond with what type. I’ll even try to make type Wheels (with capital) and wheels (without capital) the same type. To get something li…

and say we want an option to display the same reconciliation from the previous year as well.

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

If you create your details into a custom collection, you can call upon these details by this code:

`period.minus_1y.reconciliations.name_handle.custom.collection`

where

> period.minus\_1y

is looking into not the current period, but the period one year back (so period.minus\_1p works the same, 1 period back that is)

> reconciliations

is telling Silverfin to look at the reconciliation templates

> name\_handle

is telling Silverfin which template exactly to take (a handle of a reconciliation template is unique for each reconciliation template)

> custom.collection

is the name of the custom collection.

You can build in an info-tag that checks if the previous year exists as well, by following code:

```auto
{% comment %}create info tag with check only if there's a previous year{% endcomment %}
{% stripnewlines %}
{% if period.minus_1y.exists %}
{% ic %}
{::infotext as="hover"}
{% t "Check to display the reconciliation of previous year (will also be exported in PDF!)" %}
{:/infotext}
{% endic %}
{% input custom.show.prev_year as:boolean %}
{% endif %}
{% endstripnewlines %}

{% if custom.show.prev_year == "true" %}
  {% assign show_prev = true %}
{% endif %} 

```

We use the `{% if period.minus_1y.exists %}` statement in order to display the option (boolean) to check whether or not the details of previous year have to be printed or not (if there’s no previous year, no need to display this information!).

To display the details of previous year, the whole custom collection needs to be rebuild:

```auto
{% if show_prev %}
{% comment %}re-create the fori-loop of last year as a for-loop, calling on the custom collection of last year!{% endcomment %}
{% stripnewlines %}
{% for item in period.minus_1y.reconciliations.stock_cars.custom.items %}
  {% assign name_p = item.name | downcase | capitalize %}
  {% capture current_total_p %}total_{{ name_p }}_p{% endcapture %} 
  {% assign [current_total_p] = [current_total_p]+item.value %}
  {% assign items_array_p = items_array_p | append:name_p | append:";" %}
{% endfor %}
{% endstripnewlines %}

{% assign items_array_p = items_array_p | split:";" | uniq %}

<br />

{% stripnewlines %}
| Group last year
| Value last year
{% newline %}
|----70%----
|----30%----#+ 
{% for item in items_array_p %}
{% newline %}
  {% capture current_total_p %}total_{{ item }}_p{% endcapture %}
    | {{ item }} | {{ [current_total_p] | currency }} 
{% endfor %}
{% endstripnewlines %}

{% endif %} 

```

Be aware that in this case, we should name our variables (the ones we use to calculate for each group) differently, so that the details don’t get added to the same variables we use for the current year!

```auto
{% for item in period.minus_1y.reconciliations.stock_cars.custom.items %} 

rebuilding the forloop ... 
{% endfor %}

```

So you can always call on details that were made as database variables, meaning that info actually has been inputted into the database of your client file. Database variables usually have a `custom` in their name.  
There’s no need to take those into a result tag for instance; this cannot be done! More info here:

> [@CASE reference values across templates by using result tags](https://community.silverfin.com/t/case-reference-values-across-templates-by-using-result-tags/1157):
>
> If you want to reference a certain value or variable from recon template A in another template, there’s a way to do it with the so-called result tags in STL. They work like this (bulb just type in result and press TAB to get this preformatted code bulb): {% result 'name' content %} where the name is a shortname you can choose, and the content is the value or variable you want to reference to. Let’s say we have this variable done\_prepayments in our recon template Prepayments (which is al…

Here’s the whole code:

```auto
{% stripnewlines %}
| Name
| Value
{% newline %}
|----70%----
|----30%----#+
{% newline %}
{% fori item in custom.items %}
| {% input item.name %}
| {% input item.value as:currency %}
  {% assign name = item.name | downcase | capitalize %}
{% capture current_total %}total_{{ name }}{% endcapture %} 
{% assign [current_total] = [current_total]+item.value %}
{% assign items_array = items_array | append:name | append:";" %}
{% newline %}
{% endfori %}
{% endstripnewlines %}

{% assign items_array = items_array | split:";" | uniq %}

<br />

{% stripnewlines %}
| Group
| Value
{% newline %}
|----70%----
|----30%----#+ 
{% for item in items_array %}
{% newline %}
  {% capture current_total %}total_{{ item }}{% endcapture %}
    | {{ item }} | {{ [current_total] | currency }} 
{% endfor %}
{% endstripnewlines %}

<br />

{% comment %}create info tag with check only if there's a previous year{% endcomment %}
{% stripnewlines %}
{% if period.minus_1y.exists %}
{% ic %}
{::infotext as="hover"}
{% t "Check to display the reconciliation of previous year (will also be exported in PDF!)" %}
{:/infotext}
{% endic %}
{% input custom.show.prev_year as:boolean %}
{% endif %}
{% endstripnewlines %}

{% if custom.show.prev_year == "true" %}
  {% assign show_prev = true %}
{% endif %}

{% if show_prev %}
{% comment %}re-create the fori-loop of last year as a for-loop, calling on the custom collection of last year!{% endcomment %}
{% stripnewlines %}
{% for item in period.minus_1y.reconciliations.stock_cars.custom.items %}
  {% assign name_p = item.name | downcase | capitalize %}
  {% capture current_total_p %}total_{{ name_p }}_p{% endcapture %} 
  {% assign [current_total_p] = [current_total_p]+item.value %}
  {% assign items_array_p = items_array_p | append:name_p | append:";" %}
{% endfor %}
{% endstripnewlines %}

{% assign items_array_p = items_array_p | split:";" | uniq %}

<br />

{% stripnewlines %}
| Group last year
| Value last year
{% newline %}
|----70%----
|----30%----#+ 
{% for item in items_array_p %}
{% newline %}
  {% capture current_total_p %}total_{{ item }}_p{% endcapture %}
    | {{ item }} | {{ [current_total_p] | currency }} 
{% endfor %}
{% endstripnewlines %}

{% endif %} 

```
