CASE: give amount of an account of a previous period

Let’s say we want to display the amount of an account of the previous year in an account template.

In an account template we have the so called current_account drop, where you can get certain data from it (think of the company-drop where you can get data like name, vat_identifier, … ).

If we want to use the account number, we can use this code:

{{ current_account.number }} 

To have the value, we’ll use this code:

{{ current_account.value }} 

How can we get to the value of the same account for previous period?

We know we can get all accounts by this code:

{{ period.accounts }} 

which give the end result of all accounts available in the current period.

If we want that same result, but for the previous year, we can add the attribute `minus_1y’ to the period-drop:

{{ period.minus_1y.accounts }} 

Use minus_2p for instance to go 2 periods back.

All we need to do now, is to filter that “drop” of accounts on the current account, and that can be done by the range-tag, like this and our current_account.number :

{{ period.minus_1y.accounts | range:current_account.number }}