# CASE: Rollforward a collection across different income years

**URL:** <https://community.silverfin.com/t/case-rollforward-a-collection-across-different-income-years/2563>\
**Category:** Cases\
**Created:** [May 9, 2025, 12:38pm UTC](https://community.silverfin.com/t/case-rollforward-a-collection-across-different-income-years/2563 "2025-05-09T12:38:09Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benjamin\_Langenaken](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/benjamin_langenaken/32/2162_2.png) [@Benjamin\_Langenaken](https://community.silverfin.com/u/Benjamin_Langenaken)\
**Post date:** [May 9, 2025, 12:38pm UTC](https://community.silverfin.com/t/case-rollforward-a-collection-across-different-income-years/2563/1 "2025-05-09T12:38:09Z")

</div>

When [rollforwarding data](https://developer.silverfin.com/docs/rollforward) 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**

![](https://lh7-qw.googleusercontent.com/docsz/AD_4nXfEvagV_ZMDvF6Tty9Zk6KiivSDdyvYjPkPefNuSKfEgxnE5jlo40kZzrJlhuS8FFwMo3S4qUyq_wKZsCp2xyFRnARUq8z-X0zvuOxMQRsQd8SM8NsKA__KU_o6Cl7mHMZZ1iFUBw?key=cFV-Hpz0kAzW-BgzD3t6JA)

## **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.

![](https://lh7-qw.googleusercontent.com/docsz/AD_4nXdWWMSK3QBDGiXrOfMbGqW8Yky9-GVQFLnyCn99UqbNDDJPab4plWiYU3y-4M0ArIftHlOFQzHV7RQSjKIN-JzL-dtYSA4YOdd1VN6FHlwLfmKyKRGaXxoVkbDviHkIHglnO6Jfhg?key=cFV-Hpz0kAzW-BgzD3t6JA)

# **Code Breakdown**

## **Defining Income Years**

```auto
{% 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 of `period.year_end_date` formatted as “YYYY”
- `previous_income_year` is set to the year of `period.minus_1y.year_end_date` (one year prior to the current period’s end date) formatted as “YYYY”

## **Rollforward Condition Variables**

```auto
{% 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](https://developer.silverfin.com/docs/rollforward#rollforwardperiod)

## **Add Collection Current Year**

```auto
<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&nbsp;{{ 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 accumulating `item.expense_current_year` values.
- Finally, it displays the total expenses at the bottom of the table.

## **Add Collection Previous Year**

```auto
<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&nbsp;{{ 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**

```auto
{% 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 to `nil`, clearing the previous year’s expense data  
**! It’s important to empty this collection first before adding data from `custom.my_collection_cy` !**
- Then, it iterates through `custom.my_collection_cy` and also a rollforwards to `nil`, clearing the current year’s expense data
- Finally, if `fiscal_year_to` is greater than `fiscal_year_from` (meaning a rollforward should occur), it captures a dynamic key `key_py` and performs a `rollforward` operation to move the `item.expense_current_year` value to `custom.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](https://developer.silverfin.com/docs/rollforward).
