Assign a custom numbering to begin repeat

Hi, am in need of some assistance here. I have a begin repeat where for every new group added, i need to assign an auto custom numbering in the form of; 001, 002, 003....and so on. This auto assign should be under the "Asset Code". I have shared the link below.
https://docs.google.com/spreadsheets/d/1uRfszVXxrJKKsky4-iNqBvBfVDQ_-nGpbQK4-YywomM/edit?usp=sharing

Hi,

You can use the position() to find out the position in the repeat group (1, 2, 3 etc). Note that there is a difference in position() and position(..) which maybe someone else can explain better than me but its best to test this well to make sure it works as intended in your form structure. You could use concat() to include this number in the asset code format you need.
https://docs.getodk.org/form-logic/#calculations

However the design you are aiming for means that the enumerator could potentially select the same asset twice or forget one altogether. I don't know exactly how you will use the form or if all questions are asked at all households but there are other ways to do that if needed. By this I mean replacing the first select_one question with a calculation which according to the position in the repeat group picks the relevant asset name from the choice list.

1 Like

Some additional explanation on this solution please.

I added a couple lines to your example to indicate better what I meant by the second option. The second option works only if all 16 questions can be answered for all households but if that is the case, it does it in a better way than option 1. Note that I adjusted based on 3 possible options instead of 16 just for speed.

I tried you second solution but couldn't get it to work. Then tried your first solution and used count instead of position then performed a calculation (with name 'asset-code-count') outside of the repeat and passed the result to the calculation column of asset code like so:

concat("00",${asset-code-count})

and it worked.
Now the big task is how to stop the enumerator from selecting the same "Type of asset" more than once.

Got the solution for not repeating select one in a repeat group from here.
https://forum.getodk.org/t/duplicate-value-in-repeat-group-question/11281/3?u=coderscoven

Also tried the position() and it also works so will use it. Thanks @noel_cartong