Adding a calculation based on previous answers and a constraint

Hi, I am tryin to add a calculation in XLSform based on previous answers. The idea is that the total number of household hhsize shouldn't be higher than the disaggregated subgroup of babies, adults and elders: babies f_2, adults_f_517, elders_f_1860

So the sum shouldn't be higher than . = ${hhsize}

(${babiesf_2}+${adults_f_517}+${elders_f_1860}

Not sure how this can work. Thanks!

If elders_f_1860 is the last data point of dis-aggregate subgroup then you can put a constraint in this row ${babiesf_2}+${adults_f_517}+${elders_f_1860}=${hhsize}

There are a number of slightly different approaches you can take. The simplest, which is applicable if all three questions are required - and therefore must be answered in order - is, as @ARIF_AZAD_KHAN correctly states, to put a constraint on the last one to ensure the total sum remains under the prescribed limit. A subtle problem with this approach is it doesn't actually prevent you from exceeding the limit on the very first question (!). Or the second... Also, because you are entering numbers, yet counting things, you might want to prevent the user entering negative numbers (which would offset a greater than max elders count, for example).

So a slightly more robust solution would be to have an explicit constraint on each and every operand of the total; eg

${babiesf_2}: constraint = (. >= 0) and (${babiesf_2} + ${adults_f_517} + ${elders_f_1860} <= ${hhsize})

et al.