# Adding variables inside different loops depending on the iteration

**URL:** <https://community.silverfin.com/t/adding-variables-inside-different-loops-depending-on-the-iteration/2163>\
**Category:** Reports\
**Tags:** for\_loop\
**Created:** [October 13, 2021, 1:57pm UTC](https://community.silverfin.com/t/adding-variables-inside-different-loops-depending-on-the-iteration/2163 "2021-10-13T13:57:36Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shellldon](https://avatars.discourse-cdn.com/v4/letter/s/a6a055/32.png) [@shellldon](https://community.silverfin.com/u/shellldon)\
**Post date:** [October 13, 2021, 1:57pm UTC](https://community.silverfin.com/t/adding-variables-inside-different-loops-depending-on-the-iteration/2163/1 "2021-10-13T13:57:36Z")

</div>

Hello,

I am trying to create a custom fixed asset note which loops over the account codes for values depending on if the items are selected (line 42). I am having a problem with the column total (lines 113 - 115). I am trying to capture the first iteration value as a variable (line 90) to add to the second loops same iteration (line 105) and then call the value in another loop (line 115).

```auto
{% comment %}

Recording variables

{% endcomment %}

{% assign fixed_assets = "Land and buildings | Leasehold improvements | Investment property | Assets under construction | Plant and machinery | Vehicles | Fixtures and fittings | Tools and equipment | Office equipment | Other property plant and equipment" | split:"|" %}
{% comment %}Costs/Valuation{% endcomment %}
{% assign asset_opening_cost = "Dummy;110000;110100;110960;110200;110300;110400;110500;110600;110700;110800" | split:";" %}
{% assign asset_additions_cost = "Dummy;110001;110101;110961;110201;110301;110401;110501;110601;110701;110801" | split:";" %}
{% assign asset_disposals_cost = "Dummy;110002;110102;110962;110202;110302;110402;110502;110602;110702;110802" | split:";" %}
{% assign asset_revaluation_cost = "Dummy;110003;110103;110963;110203;110303;110403;110503;110602;110703;110803" | split:";" %}

{% comment %}

Start display

{% endcomment %}

{% stripnewlines %}
{% ic %}{::infotext}{% newline %}
Additions and disposals are populated from the {% linkto period.reconciliations.fixed_assets_reconciliation %}{{ period.reconciliations.fixed_assets_reconciliation.name }}{% endlinkto %}{% newline %}
{:/infotext}{% endic %}

{% endstripnewlines %}

{% ic %}{% stripnewlines %}
| Show/Hide

{% newline %}
|--
  {% for select_lines in fixed_assets %}
    |--
  {% endfor %}
|--#

{% newline %}
  {% for asset_select in fixed_assets %}
    |{% input custom.[forloop.index].box as:boolean %} <br> {{ asset_select }}
  {% endfor %}

{% endstripnewlines %}

<br><br>

{% endic %}{% stripnewlines %}
| 
{% for asset_headers in fixed_assets %}
  {% if custom.[forloop.index].box %}
  |{{ asset_headers }}
  {% endif %}
{% endfor %}
| Total

{% newline %}
|--------
{% for main_table_lines in fixed_assets %}
  {% if custom.[forloop.index].box %}
  |---10%---:
  {% endif %}
{% endfor %}
|--------:+

{% newline %}
| 
  {% for pound_sign in fixed_assets %}
   {% if custom.[forloop.index].box %}
   | £
   {% endif %}
  {% endfor %}
| £

{% comment %}Cost/valuation{% endcomment %}
{% comment %}Cost/valuation{% endcomment %}
{% comment %}Cost/valuation{% endcomment %}

{% newline %}
| **Cost / valuation**

{% newline %}
|At {{ period.year_start_date | date:"%d %B %Y"}}
  {% for asset_cost in fixed_assets %}
   {% if custom.[forloop.index].box %}
   {% assign opening_cost = period.accounts | range:asset_opening_cost[forloop.index] %}
   |{{ opening_cost | currency }} {% $1+ opening_cost %}
   
   {% capture asset_cost[forloop.index] %}{{ opening_cost }}{% endcapture %}
   
   {% endif %}
  {% endfor %}
| {{ $1 | currency }}

{% comment %}Disposals{% endcomment %}

{% newline %}
|Disposals
  {% for asset_disposals in fixed_assets %}
   {% if custom.[forloop.index].box %}
   {% assign disposals_cost = period.accounts | range:asset_disposals_cost[forloop.index] %}
   |{{ disposals_cost | currency }} {% $4+ disposals_cost %}
   
   {% capture total_cost[forloop.index] %} asset_cost[forloop.index]+ disposal_cost{% endcapture %}
   
   {% endif %}
  {% endfor %}
| {{ $4 | currency }}

{% newline %}
| **At {{ period.year_end_date | date:"%d %B %Y"}}**
  {% for asset_disposals in fixed_assets %}
   {% if custom.[forloop.index].box %}
   |{{ total_cost.[forloop.index] | currency }} 
   {% endif %}
  {% endfor %}
|
{% endstripnewlines %}

```

---

<div class="post-metadata">

**Author:** ![Thomas\_Thomsen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/thomas_thomsen/32/1046_2.png) [@Thomas\_Thomsen](https://community.silverfin.com/u/Thomas_Thomsen)\
**Post date:** [October 13, 2021, 3:31pm UTC](https://community.silverfin.com/t/adding-variables-inside-different-loops-depending-on-the-iteration/2163/2 "2021-10-13T15:31:50Z")

</div>

Hi Shellldon

I have added 5 lines of code wich should fix your issue with the totals.

Best regards

{% comment %}

Recording variables

{% endcomment %}

{% assign fixed\_assets = “Land and buildings | Leasehold improvements | Investment property | Assets under construction | Plant and machinery | Vehicles | Fixtures and fittings | Tools and equipment | Office equipment | Other property plant and equipment” | split:"|" %}  
{% comment %}Costs/Valuation{% endcomment %}  
{% assign asset\_opening\_cost = “Dummy;110000;110100;110960;110200;110300;110400;110500;110600;110700;110800” | split:";" %}{% assign asset\_opening\_cost = “Dummy;81;82;83;84;110300;110400;110500;110600;110700;110800” | split:";" %}  
{% assign asset\_additions\_cost = “Dummy;10;10;10;110201;110301;110401;110501;110601;110701;110801” | split:";" %}  
{% assign asset\_disposals\_cost = “Dummy;10;10;10;110202;110302;110402;110502;110602;110702;110802” | split:";" %}  
{% assign asset\_revaluation\_cost = “Dummy;110003;110103;110963;110203;110303;110403;110503;110602;110703;110803” | split:";" %}

{% comment %}

Start display

{% endcomment %}

{% stripnewlines %}  
{% ic %}{::infotext}{% newline %}  
Additions and disposals are populated from the {% linkto period.reconciliations.fixed\_assets\_reconciliation %}xxx{% endlinkto %}{% newline %}  
{:/infotext}{% endic %}

{% endstripnewlines %}

{% ic %}{% stripnewlines %}  
| Show/Hide

{% newline %}  
|–  
{% for select\_lines in fixed\_assets %}  
|–  
{% endfor %}  
|–#

{% newline %}  
{% for asset\_select in fixed\_assets %}  
|{% input custom.[forloop.index].box as:boolean %}   
 {{ asset\_select }}  
{% endfor %}

{% endstripnewlines %}

{% endic %}{% stripnewlines %}  
|  
{% for asset\_headers in fixed\_assets %}  
{% if custom.[forloop.index].box %}  
|{{ asset\_headers }}  
{% endif %}  
{% endfor %}  
| Total

{% newline %}  
|--------  
{% for main\_table\_lines in fixed\_assets %}  
{% if custom.[forloop.index].box %}  
|—10%—:  
{% endif %}  
{% endfor %}  
|--------:+

{% newline %}  
|  
{% for pound\_sign in fixed\_assets %}  
{% if custom.[forloop.index].box %}  
| £  
{% endif %}  
{% endfor %}  
| £

{% comment %}Cost/valuation{% endcomment %}  
{% comment %}Cost/valuation{% endcomment %}  
{% comment %}Cost/valuation{% endcomment %}

{% newline %}  
| **Cost / valuation**

{% newline %}  
|At {{ period.year\_start\_date | date:"%d %B %Y"}}  
{% for asset\_cost in fixed\_assets %}  
{% if custom.[forloop.index].box %}  
{% assign opening\_cost = period.accounts | range:asset\_opening\_cost[forloop.index] %}  
|{{ opening\_cost | currency }} {% $1+ opening\_cost %}

{% capture asset\_cost[forloop.index] %}{{ opening\_cost }}{% endcapture %}  
{% capture total\_col %}total\_{{ asset\_cost }}{% endcapture %}  
{% assign [total\_col] = [total\_col]+opening\_cost %}  
{% endif %}  
{% endfor %}  
| {{ $1 | currency }}

{% comment %}Disposals{% endcomment %}

{% newline %}  
|Disposals  
{% for asset\_disposals in fixed\_assets %}  
{% if custom.[forloop.index].box %}  
{% assign disposals\_cost = period.accounts | range:asset\_disposals\_cost[forloop.index] %}  
|{{ disposals\_cost | currency }} {% $4+ disposals\_cost %}

{% capture total\_cost[forloop.index] %} asset\_cost[forloop.index]+ disposal\_cost{% endcapture %}  
{% capture total\_col %}total\_{{ asset\_disposals }}{% endcapture %}  
{% assign [total\_col] = [total\_col]+disposals\_cost %}

{% endif %}  
{% endfor %}  
| {{ $4 | currency }}

{% newline %}  
| **At {{ period.year\_end\_date | date:"%d %B %Y"}}**  
{% for asset\_disposals in fixed\_assets %}  
{% if custom.[forloop.index].box %}  
|{% capture total\_col %}total\_{{ asset\_disposals }}{% endcapture %}{{ [total\_col] | currency }}

{% endif %}  
{% endfor %}  
|  
{% endstripnewlines %}
