When rollforwarding data across income years you can use separate collections for each year.
But how do you move this data from one collection to the next?
Let’s walk through the steps below.
Visual representation
Income year 2024
Income year 2025
As you can see below, after performing the rollforward on the platform, the new
collection for the current year will become empty.
Furthermore, the expense data from 2024 will be added to the previous year’s collection.
Code Breakdown
Defining Income Years
{% assign income_year = period.year_end_date | date:"%Y" %}
{% assign previous_income_year = period.minus_1y.year_end_date | date:"%Y" %}
These lines define the current and previous income years.
income_year
is set to the current income year ofperiod.year_end_date
formatted as “YYYY”previous_income_year
is set to the year ofperiod.minus_1y.year_end_date
(one year prior to the current period’s end date) formatted as “YYYY”
Rollforward Condition Variables
{% assign fiscal_year_from = period.year_end_date | date:"%Y" %}
{% assign fiscal_year_to = rollforward.period.year_end_date | date:"%Y" %}
These variables are used to determine if a rollforward should occur.
fiscal_year_from
is set to the current income year, formatted as “YYYY”fiscal_year_to
is set to the year the data is being rollforwarded to, formatted as “YYYY”
Rollforward.period
is useful if you only want to roll forward data in specific cases
More info on this topic can be found here
Add Collection Current Year
<table class="usr-width-25 usr-bordered">
<thead>
<tr>
<th>Expenses</th>
<th>{{ income_year }}</th>
</tr>
</thead>
<tbody>
{% fori item in custom.my_collection_cy %}
{% capture expense_number %}Expense {{ forloop.index }}{% endcapture %}
<tr>
<td>{{ expense_number }}</td>
<td>{% input item.expense_current_year as:currency placeholder:0 %}</td>
</tr>
{% assign total_expenses_current_year = total_expenses_current_year+item.expense_current_year | currency %}
{% endfori %}
<tr>
<td class="usr-line-top"><b>Total Expenses</b></td>
<td class="usr-line-top"><b>{{ total_expenses_current_year }}</b></td>
</tr>
</tbody>
</table>
This section generates an HTML table to display expenses for the current year.
- It loops through a collection called
custom.my_collection_cy
. - For each item, it generates a row with an “Expense [index]” label and an input field for
item.expense_current_year
(formatted as currency). - It calculates
total_expenses_current_year
by accumulatingitem.expense_current_year
values. - Finally, it displays the total expenses at the bottom of the table.
Add Collection Previous Year
<table class="usr-width-25 usr-bordered">
<thead>
<tr>
<th>Expenses</th>
<th>{{ previous_income_year }}</th>
</tr>
</thead>
<tbody>
{% fori item in custom.my_collection_py %}
{% capture expense_number %}Expense {{ forloop.index }}{% endcapture %}
<tr>
<td>{{ expense_number }}</td>
<td>{% input item.expense_previous_year as:currency placeholder:0 %}</td>
</tr>
{% assign total_expenses_previous_year = total_expenses_previous_year+item.expense_previous_year | currency %}
{% endfori %}
<tr>
<td class="usr-line-top"><b>Total Expenses</b></td>
<td class="usr-line-top"><b>{{ total_expenses_previous_year }}</b></td>
</tr>
</tbody>
</table>
This section is very similar to the previous section but generates an HTML table to display expenses for the previous year.
Add Rollforward Logic
{% comment %}First we need to empty the collection of the previous year{% endcomment %}
{% comment %}This collection can then be filled with the data from the current year when rollforwarding to the next year{% endcomment %}
{% for item in custom.my_collection_py %}
{% rollforward nil item.expense_previous_year %}
{% endfor %}
{% for item in custom.my_collection_cy %}
{% rollforward nil item.expense_current_year %}
{% if fiscal_year_to > fiscal_year_from %}
{% capture key_py %}my_collection_py_{{ forloop.index }}{% endcapture %}
{% rollforward item.expense_current_year custom.my_collection_py.[key_py].expense_previous_year %}
{% endif %}
{% endfor %}
This section handles the rollforward logic.
- First, it iterates through
custom.my_collection_py
and performs a rollforward tonil
, clearing the previous year’s expense data
! It’s important to empty this collection first before adding data fromcustom.my_collection_cy
! - Then, it iterates through
custom.my_collection_cy
and also a rollforwards tonil
, clearing the current year’s expense data - Finally, if
fiscal_year_to
is greater thanfiscal_year_from
(meaning a rollforward should occur), it captures a dynamic keykey_py
and performs arollforward
operation to move theitem.expense_current_year
value tocustom.my_collection_py.[key_py].expense_previous_year
, effectively copying the current year’s expense data to the previous year’s collection in the next income year
Wrapping up
By following the steps above, you can effectively roll forward your data from one collection to the other across income years. This rollforward logic ensures that your previous year’s collection is cleared and correctly updated with the current year’s data, while keeping your current year collection ready for fresh entries.
For other rollforward scenarios, be sure to check out the Silverfin Developer Docs.