Using an if() condition calculation to calculate the count() whcih is passed to repeat_count?

1. What is the issue? Please be detailed.
if(${trans_type} = 'out' and ${select_reason} = 'sale' , count(instance('linking_check')/root/data[uuid = ${reason_uuid}]/product) , ' ')
I am using the following formula , it is working fine but when the trans_type and select_reason changes to anything other where i want that there should be no repeat_count limit and the repeat group works manualy , it is not showing the repeat group.

3. What have you tried to fix the issue?
check on forum but can't find any solution.

4. Upload any forms or screenshots you can share publicly below.

As far as I know there is no option to "deactivate" the repeat_count (limit) like this.

A workaround might be to work with an entry field where the user can manually set a number for the repeat count. This field can be controlled by your if clause, either by required or calculation with once() as preset.

Then the repeat_count could use or combine the information, based on your if-calculation with else value from this manual field. (Might also be a max or min use case?)

I wonder if this is related to not removing repeat elements if repeat count is decreased.

bad idea

I hesitate to suggest this as it's pretty messy, but it might deliver what you are looking for with current functionality.

  • one repeat that uses the repeat count count(instance('linking_check')/root/data[uuid = ${reason_uuid}]/product) and repeat relevance ${trans_type} = 'out' and ${select_reason} = 'sale'
  • another repeat with no repeat count and repeat relevance ${trans_type} != 'out' or ${select_reason} != 'sale'
  • duplicate the questions in both repeats
  • use a third repeat with the count set as that of the relevant repeat
  • for each repeat element position, calculate in the value for the question from the matching position from the relevant repeat.

Actually, this is probably a much better solution, but modify the repeat_count expression to something like this, where it's set to your lookup count for the out&sale case, but the user can keep +1-ing more entries for the other case.
if(${trans_type} = 'out' and ${select_reason} = 'sale' , count(instance('linking_check')/root/data[uuid = ${reason_uuid}]/product) , if(${count} = 0 or ${plant}[position()=${count}]/more_plants = 'yes', ${count} + 1, ${count}))