Dependency cycle with Once


I have seen lots of ticket for the dependency cycle issue but none about this case where the dependency error is shown with the once function but I don't think it should:
I have a repeat group where I want to have the previous repeat value filled if any, in order to do that I added Calculation [once(max(${my_var}))]

Upon execution, if there is no value then the max should return 0, After the default value is assigned, the calculation won't run because of "once" so I don't understand why we get Dependency cycle errors
for variable in the once.

Will be possible to support this kind of scenario in the future ?

Thanks in advance

Hi @delcroip
welcome to the forum! Please introduce yourself here!

Could you attach a sample form that would allow us reproducing the issue?

Can you attach a sample form so that we can see how best to help you. you may have to use index repeat to call the value you want from the previous repeat group to the new repeat group.

1 Like

once is not an ideal solution for dynamic defaults because it doesn't allow for empty values. It also is subject to this kind of dependency check issue. We recently introduced true dynamic defaults and you can read more at So you should use the default column instead of a calculation with once.

Related to the cycle issue, max(${my_var}) when it's inside of the repeat that ${my_var} is in does not do what you want it to. ${my_var} ends up getting expanded to the specific value in the current repeat instance rather than all values across the repetitions so far. To get a list of all my_var values across all repeat instances, you'll want to pull the max calculation outside of the repeat. This might actually overcome the cycle issue but I would still recommend steering clear of once and using true dynamic defaults.

Here is a sample form that demonstrates what I think you're trying to do. It's a very powerful concept!

As a side note for @martijnr, @Xiphware and other XPath enthusiasts, I've recently wondered whether max and other functions that take a nodeset should be able to deal with a contextualized reference. That is, should max(/data/outer[2]/inner[7]/my_group/my_var) be equivalent to max(/data/outer[2]/inner/my_group/my_var)? I don't believe it currently is in either Collect or Enketo, hence my suggestion to pull out the expression so it doesn't get contextualized. It seems like the function could ensure that the innermost group is always uncontextualized but that could also be considered dangerous because it would be making assumptions about intent (e.g. that I don't mean max(/data/outer/inner/my_group/my_var) which should also be valid).

Thank you @LN I will recheck with the default unsing the latest version of xlsform.

Best regards