Constraint for multiple choice answer

Hi!
I would like to have a constraint according to a multiple choice answer.
Q1: select_multiple Which are your main ....... suppliers?
According to the suppliers chose:
Q1.1: decimal: In the last season what was the approximate % of .... sourced from .... Option1, or/and 2 or/and 3?
I need to have a constraint to assure they sum up to 100%, of the suppliers selected.

I hope you can help me

Hi @Juliana_EM,
This should be very doable, yes!

One option, for example if there were 5 suppliers, is that you could have a group of 5 questions with "field-list" appearance, which would be your decimal questions asking for %. Each question would relate to one supplier, and the "relevant" column would be used to show only the questions of the suppliers they'd chosen in the multi select.

I believe the constraint would then simply be ${s1} +${s2}+${s3} +${s4} +${s5} =100.

When you swipe forward from the group of questions, the constraint should be checked, and it should warn if it doesn't add up.

I'm not at my computer right now, just sending this from my phone, sorry I haven't done an example XLSForm for you or tested it out myself for sure, but that's where I'd start. But if this sounds like what your question is, then let me know if you need more help on this!

Cheers,
Janna

2 Likes

@janna is correct! One caveat is that the input questions must be required or you must convert those answers to zero. This is because unanswered number questions are nil, not 0.

https://docs.opendatakit.org/form-logic/#empty-values has a more detailed explanation and workarounds.

2 Likes