Within Repeat - auto increment

Within a Repeat Group can we take a previous answer, perform some math on it, and use this new calculation as the default answer on the next repeat question?

Example within a Repeat Group:

integer question "Reading Number?" (user might enter 100)

then perform a calculation on ReadingNumber + 1

Next repeat question "Reading Number?" (already has 101 as default answer but user can over write as needed)

The goal is to save on data entry since the Reading Number auto increments but occasionally they will reset it to some new, unknown, integer.

I've tried to set the default for the ReadingNumber question to:
indexed-repeat(${ReadingNumber}, ${group_readings}, position(..))+1
but this doesn't work.

Thanks,
Carl

Short answer: no. Defaults must always be literal values, irrespective of whether the question happens to be within a repeat group or not. You cannot specify a calculation for a default.

What you can do instead is separate your input question and actual result. eg

type=number, name=mynumber, label="Enter a number"

and make the result a calculation of the form:

type=calculate, name=result, calculation=coalesce(${mynumber}, ${some_calculation})

That way, the final ${result} will end up being whatever the user enters for ${mynumber}, and if they dont enter anything it will pickup the 'default' value from ${some_calculation}, which can be a literal, reference to another question, or a complex calculation. You can do this likewise within a repeat group (although be careful of self-referencing the same element of a previous repeat iteration...)

Thanks. Appreciate the help.