# Calculating totals from entries in rosters within rosters with a single select Option

I have a questionnaire for listing EAs. I am listing structures in a EA. Listing means I can have >60 structures to list. within the structure, I am supposed to list all the housig units within the structure, again which can exceed 60. So in my questionnaire, I have a fixed part for the structures which can accomodate upto 60 structures within the EA, and have a list for households within that structure.
The fixed part is the base question(structure rooster) for the second roster (housing units) which is nested within the structure. The structure rooster is list all the structures in the EA. in the second rooster i list all the housing units within that structure. In the housing units I have a single select question asking if it is occupied or not. I want to have a sum of all the households that are occupied in the single EA, such that the Research assistant can know how many housing units are occupied in that EA. Is this possible to do? And if so, what would be the syntax for this calculation?

CountValue(occupied,var1,var2,var3,var4…)

You can you use CountValue .This syntax counts the number of times a value in this scenario occupation is selected in a set of enumarated variables var1, var2… it will return the number of occurrence(occupation). This will give you the number of occupied housing unit. And if there will be a scenario where in a selected EA there is no occupation then it will return 0. Hope this works.

Dear Blessing,
My questionnaire is attached.

I want the total number of housing units occupied (yes / no) if the response is yes from all the structures listed in all the cluster parts.
This should pop out in a static text like "you have listed %occ% households

"

I will be gratefull if we can get the code

The syntax is the same CountValue. first you create a variable with long integer as var-type then the expression like shown below.

then you will create a static text. ‘‘You have listed %Occupation% households’’
This will give you the total occupation per EA

@samwenda You can also set the min-max number of household being listed.

I think what @samwenda is after here, is to calculate at the ‘Interview Level’ a variable/static text that sums up all the cases where occ==1 (Assuming Yes==1).

To do this, create a variable at the interview/top level, e.g. named count_occupied_hu of type 'Long Integer`with expression

clR.SelectMany(l1=>l1.str_R.Select(l2=>l2.hnr.Count(l3=>l3.occ==1))).Sum()

This is a question asked quite often in the forum I believe, e.g. see here

As a side note: Consider to enhance this questionnaire. Per picture uploaded, it seems that you could still improve interviewer experience and reduce likelihood of data entry errors, e.g. through adding more validations to this questionnaire as a starter. For example, if the Housing Unit Number needs to follow a particular pattern, you could add a validation to hu_nu. Or enforcing no duplicate entries, see here for related discussion.

Dear Peter,
This works perfectly well.

Out of curiosity, I would want the serial numbers to follow ascending order from the first number of entries. For example, the list question to trigger the rooster is listing all the structures serially, but with different starting numbers

To be more elaborate assume am listing 350 structures within the EA. In the cluster, part rooster, am only limited to listing 60 structures. so in the first cluster part 1 would want the serialization to start from 1,2,…60 ; [the rooster type here being triggered by a fixed set of items]
in the second cluster part 2, I would want the system to start with numbers 61,62,…,120 same case to the third, fourth fifth, and sixth parts. In that case, I will have all my 350 structures listed serially but in different parts of the cluster parts.

On the housing unit numbers, I would wish to list them sequentially starting from numbers 1,2…,60
I would appreciate any help.[rooster being triggered by list structure number question]

Any help on how to do this?

Hello @samwenda,

please see the example in PUBLIC DEMO Listing sequentially.

Best, Sergiy

2 Likes

Besides the technical implementaton that Sergiy highlighted, I would recommend to at least consider changing your approach in the first place:

Why do you want to have interviewers listing a sequential number? These kind of things can always be done by a machine during the interview process or after (In fact, SuSo already assigns in the ‘backend’ a unique roster__id to each of the listed structures/units.

What I am after here: Consider instead of listing a structure number, a short description of the structure! Like “Red House next to Church”. This way you get extra data points which might be very useful down the road (especially if lsting data is used for assignments and interviewers change in the meantime).

Or for Housing Units inside a structure, enforce a pattern like “# of floor - short description”, like “2 - Brown Door on the right”.

You then can still assign a dedicated ID after you receive the data.

Again, just a recommendation to at least consider, I have no further insights in your field approach, so the current questionnaire can be the perfect fit already!.

Dear Peter

We are doing a listing of all the structure and we must allocate the numbers on the ground to the survey form. Thats why we have to list the structure numbers and housing unit numbers sequentially.

The solution you provided works, and am thankful