In need of help regarding to how create and utilize a count variable such that a set of questions only repeats for every 10th household

Hi! I want to go about a CommCare survey such that a set of questions only repeat for every tenth household/household member that opens the form. What functions should I be using to go about doing this?

Copying over @Simon_Kelly 's answer from StackExchange in case anyone finds this thread via search in the future:

There is no way to do this across all users of your application but you can do it for each user.

You can create an incrementing counter on the User Case and use that to determine when to show the questions.

Instructions for incrementing a counter can be found here: Incrementing a counter - CommCare Public - Dimagi Confluence

1 Like

Thanks for your help @Clayton_Sims and @Simon_Kelly!

Hi @Simon_Kelly and @Clayton_Sims, many thanks for your help! I have a follow up question regarding my counter variable, form_count, which I have set as follows:

I am trying to use this variable in the "Display Condition" for certain questions such that the those questions only appear when every tenth household member fills out the form. However, that seems rather tedious to write in the logic if I am accounting for every 10th number up to my sample size (200). See sample screenshot below for what I mean.

Is there a better way to go about doing this?

Thank you for your time and for all of your help!

There's a modulo operator within the evaluation language, so you can make your display condition something like

#form/form_count mod 10 = 0

to make the question or group only display when the form count is 10, 20, etc

1 Like

Many thanks for your help @Clayton_Sims !

Hi @Clayton_Sims , thanks again for your help. What does the "= 0" of the operator signify? Thanks again for all of your help!

Hi @JZUser95
You can read more about the modulo operator on the functions help page.
This operator gives the remainder - x mod y, gives the remainder when x is divided by y. If the remainder is "0", it means x is exactly divisible by y, or in your case, that that number is a multiple of 10.

Hope that helps!

1 Like

Many thanks for your help @Farid_Rener!

Hi @Clayton_Sims, @Simon_Kelly, and @Farid_Rener, many thanks for your help. Is there a way to set the counter such that a set of questions repeat for every 10th household form submitted by each mobile user separately (e.g.)

Mobile User 1: Submits 10 household forms; 10th household form has the set of questions that repeat every 10th household.

Mobile User 2: Separately, mobile user 2 submits 10 household forms, and the 10th household form has the set of questions that repeat every 10th household.

Currently, the counter seems to count forms submitted across all mobile users, rather than just individual mobile users.

Thanks for all of your help!

Each User Case should only track their data (including counters like this) for their personal user case.

Are all of your mobile users using distinct mobile user accounts?