Displaying a note - with a calculation result in it

Hi

I'm trying to find a way to complete the following task.

The person who is conducting a household level survey - asks how many people are living in the house - Answer X

They then ask about each age group. 0 - 5yr = A, 5- 18 = B etc

I would like to then complete a "sense check"

To display a note that says the following:

You entered ${n_total_members} as total members in group.
From the numbers you entered the total members count is ${n_total_members_calculated}.
Please check the equality of those numbers and acknowledge accordingly.

And i would like them not to be able to complete the form until the two numbers match.
i'm unable to attach the form as a new user so here is my best attempt at copy and paste for you.

type name label required relevant calculation
integer n_total_members Total number of members living now under the same roof (INCLUDING Head of Household) yes
end group
begin group ages_part_one Ages
select_one num w_over60 Total number of WOMEN over age 60 yes
select_one num m_over60 Total number of MEN over age 60 yes
select_one num w_over18 Total number of WOMEN between age 18 to 60 yes
select_one num m_over18 Total number of MEN between age 18 to 60 yes
end group
begin group ages_part_two Ages
select_one num g_over15 Total number of GIRLS age 14 - 17 yes
select_one num b_over15 Total number of BOYS age 14 - 17 yes
select_one num g_over5 Total number of GIRLS age 5 - 13 yes
select_one num b_over5 Total number of BOYS age 5 - 13 yes
select_one num g_under4 Total number of GIRLS age 0 - 4 yes
select_one num b_under4 Total number of BOYS age 0 - 4 yes
calculate n_total_members_calculated ${w_over60}+${m_over60}+${w_over18}+${m_over18}+${g_over15}+${b_over15}+${g_over5}+${b_over5}+${g_under4}+${b_under4}
note entry_check "You entered ${n_total_members} as total members in group.
From the numbers you entered the total members count is ${n_total_members_calculated}.
Please check the equality of those numbers and acknowledge accordingly." ${n_total_members}!=${n_total_members_calculated}

Currently the calculation works - when i download the raw data i can see it works fine.

The only issue is the entry_check. Any ideas?

Thanks in advance for your help

Nick

Hi @nickrenn
I think you need to add a constraint column to your sheet https://opendatakit.org/help/form-design/binding/ and then add something like ${n_total_members} = ${n_total_members_calculated} if I understand. if you have a problem with it please attach your form using eg google sheets then I can help you.

Regards,
Grzegorz

It won't let me upload as a new user yet. I have a constraint column in the full version i'll add what you've said above and see what happens and let you know - once they let me upload the doc i will do.

thanks for the response

You are not able to attach a link to google sheet?

good point :slight_smile:
https://docs.google.com/spreadsheets/d/1VY4apvv8EXo-o3ucFN3nI_8zowzOSaRjAdF1j_VahP8/edit?usp=sharing

I tested your form and I found out we are not able to use constraint with note type moreover we even are not able to use constraint when a question is readonly and if we don't pass any answer it doesn't work too...
constraint.xml (1.3 KB)
constraint.xlsx (5.4 KB)

in other words it works only if the question has an answer.

@yanokwa @LN is it a known bug?

I think the idea with constraints is that they can only be applied to fields that can be changed. That makes sense to me.

I would tend to put the constraint on the last age question as in calculate-test.xlsx (6.8 KB)

What about the fact it doesn't work if we leave such a question without any answer? I know we can add required=true() but still. Is it ok?

@Grzesiek2010 That seems intentional to me -- it makes it possible to represent a case when a value may not be known but if it is known must meet certain characteristics. For example, I can imagine a question that asks for a child's age. The age can be left blank but if it is filled in, it must be 18 or below. That question would not be required and would have a constraint that should only be evaluated if a value is given.

@nickrenn we've strayed a little bit from your initial question! Let us know whether putting the constraint on the last age question can work for you.

1 Like

Hi All

Sorry for the very late reply on this, basically turns out the issue is that i'm acutally using survey123 which has limited function currently and is unable to do what i want.

But to answer my own question :slight_smile: if you make all answers required and as such number of people in any age group have a numeric value of 0 or greater, it does work in ODK. the Entry Check function as a requirement will stop the form being submitted until the "Total Members" and "Total Calculated Members" are equal to each other.

I've tried it out on ODK and had now issues.

Thanks for the initial feedback.