# Fori in For Loop \> duplicated values

**URL:** <https://community.silverfin.com/t/fori-in-for-loop-duplicated-values/1720>\
**Category:** Templates\
**Created:** [March 31, 2020, 12:51pm UTC](https://community.silverfin.com/t/fori-in-for-loop-duplicated-values/1720 "2020-03-31T12:51:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Abo](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Abo](https://community.silverfin.com/u/Abo)\
**Post date:** [March 31, 2020, 12:51pm UTC](https://community.silverfin.com/t/fori-in-for-loop-duplicated-values/1720/1 "2020-03-31T12:51:01Z")

</div>

Hi,

Could you please assist in below, each value of the input fields (in the fori) are duplicated if there’s a second value on the for loop. How can we resolve this:

{% for rekeningen2 in selected2 %}

{% stripnewlines %}  
| {% t “Description” %}  
| {{ period.minus\_1y.year\_end\_date |date:’%d/%m/%Y’ }}  
| {% t “InCo” %} ({% t “P&L” %})  
| {% t “RePa” %}  
| {{ period.year\_end\_date |date:’%d/%m/%Y’ }}  
{% newline %}  
|—40%-----  
|:—15%-----:  
|:—15%-----:  
|:—15%-----:  
|—15%-----:+  
{% newline %}  
| {{ rekeningen2.original\_number }} {{ rekeningen2.original\_name as:text }}   
| {% assign valuepy2 = rekeningen2.opening\_value as:currency %} {{ valuepy2 | currency }}   
|  
|  
| {% assign valuecy2 = rekeningen2.value as:currency %} {{ valuecy2 | currency }}   
{% capture reken\_key %}reken\_{{ rekeningen2.key }}{% endcapture %}  
{% fori newitem in custom[reken\_key] %}  
{% newline %}  
| {% input newitem.description2 as:text required:true placeholder:‘Description’ %}  
| {% $4+input newitem.amount2 as:currency %}  
| {% $5+input newitem.InCo2 as:currency %}  
| {% $6+input newitem.RePa2 as:currency %}  
| {% =$7+ newitem.amount2+newitem.InCo2+newitem.RePa2 as:currency %}  
{% endfori %}  
{% newline %}  
| **{% t “reconcile” %}**  
| {% unreconciled valuepy2-$4 as:indicator unreconciled\_text:“Still to reconcile” %} **{{ valuepy2-$4 | currency }}**  
|  
|  
| {% unreconciled valuecy2-$7 as:indicator unreconciled\_text:“Still to reconcile” %} **{{ valuecy2-$7 | currency }}**  
{% endstripnewlines %}

{% endfor %}

---

<div class="post-metadata">

**Author:** ![Melle](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/melle/32/1312_2.png) [@Melle](https://community.silverfin.com/u/Melle)\
**Post date:** [March 31, 2020, 2:02pm UTC](https://community.silverfin.com/t/fori-in-for-loop-duplicated-values/1720/2 "2020-03-31T14:02:37Z")

</div>

In your for loop, you are iterating over an accounts collection, which means you should use .id instead of .key:

```
{% capture reken_key %}reken_{{ rekeningen2.id }}{% endcapture %}

```

This will generate different names for [reken\_key] each iteration, so the duplicates won’t show anymore.

Don’t hesitate to ask if you still encounter some problems!

---

<div class="post-metadata">

**Author:** ![Abo](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Abo](https://community.silverfin.com/u/Abo)\
**Post date:** [March 31, 2020, 2:24pm UTC](https://community.silverfin.com/t/fori-in-for-loop-duplicated-values/1720/3 "2020-03-31T14:24:01Z")

</div>

Thank you !

---

<div class="post-metadata">

**Author:** ![Abo](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@Abo](https://community.silverfin.com/u/Abo)\
**Post date:** [April 1, 2020, 12:53pm UTC](https://community.silverfin.com/t/fori-in-for-loop-duplicated-values/1720/4 "2020-04-01T12:53:08Z")

</div>

Could you please assist in the following. In the post above we succeeded to use the fori loop.

But now we want show the collected info in a forloop see below:

{% for newitem in custom.[reken\_key] %} {% if $1 != blank %}  
{% newline %}  
| {{ newitem.description2 }}  
| -{{ newitem.InCo2 | currency }}  
| {% input newitem.Ref as:text placeholder:“Notes” %}  
| {% input newitem.Other as:file %}  
{% endif %}  
{% endfor %}

For one or other reason it shows only the two last records (3&4 and not the first and second), no clue why ?

Thx for assistance.

---

<div class="post-metadata">

**Author:** ![Melle](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/melle/32/1312_2.png) [@Melle](https://community.silverfin.com/u/Melle)\
**Post date:** [April 1, 2020, 3:26pm UTC](https://community.silverfin.com/t/fori-in-for-loop-duplicated-values/1720/5 "2020-04-01T15:26:25Z")

</div>

In order to answer your question, I would like to know how you defined [reken\_key] before iterating over the collection.

Like in your initial post, first a capture statement like `{% capture reken_key %}reken_{{ rekeningen2.id }}{% endcapture %}` should be used to define the exact identity of the custom.[reken\_key] collection you want to loop over.
