# Calculation on repeat inside another repeat

Hi ODK community,

I've been looking for solutions to my problem in the forum but I can't find anything. I don't know how to deal with it.

1. What is the problem? Be very detailed.
I am building a form to register the plots of one farmer and in each plot we register the species in it.
So the form is like this :
-Farmer info
-repeat plots (location)
-repeat species (species name, species number of trees)

So I have a repeat inside another repeat.

I want to sum the number of trees per plots. I add a calculate question inside the first repeat but unfortunatly whenever I register another plot, the calculate question also add the number of trees of the previous plot.

5. Anything else we should know or have? If you have a test form or screenshots or logs, attach below.
Here you have a simplified version of my form.
sum_on_repeat.xlsx (11.5 KB)

Any help would be highly appreciated.

Thank you

1 Like

Hi and welcome, @Fabien_Pageot! Please take a moment to share a little about yourself and your project at Introduce yourself here! I'm guessing you already know @mathieubossaert and his work but if not, I think you would find ODK to collect species and habitats localities, as pressure and threats to ecosystems related to what you're doing.

I believe you are likely trying this form out in Enketo, is that right? I believe it will work as expected in ODK Collect.

It looks like the sum calculation is being output as `sum(/data/plot_registration/species_registration/species_nb)` from the XLSForm to XForm converter. However, it should be output as `sum(../species_registration/species_nb)`. You should be able to change `sum(\${species_nb})` to `sum(../species_registration/species_nb)` in your XLSForm to get the desired behavior.

nested-repeat-sum is a further simplified form definition. The sum calculation is output as `sum( /data/outer/inner/number )`. @martijnr does this look like a `pyxform` bug to you as well?

1 Like

Thank you a lot @LN !

I've changed sum(\${species_nb}) to sum(../species_registration/species_nb) and now it works.