Constraint, fields must add up to 10, conditional questions

Hi all, would greatly appreciate any help!

1. What is the problem? Be very detailed.
The problem is that I'm trying to add a constraint so that the answers on that page must add up to 10. But with two caveats: for various reasons, i) I must use select_one, not integer for those questions, and ii) those questions have relevant clause conditional on an earlier question. I know how to make it work if it weren't for those relevant clause, which seem to interfere with the constraint calculation. As a result, I cannot get the constraint to work.

The problematic cells are highlighted here: GMLGhana_test.xlsx (50.5 KB)

2. What app or server are you using and on what device and operating system? Include version numbers.
Using XLS form, ODK collect v1.27.2

Thanks so much!!
Xue

Hi @Xue
welcome to the forum! Please introduce yourself here!
the way you calculate percents is wrong. you use number function which is for calculating dates. You need to use something ugly like:

if(selected(${d1},'1'),10,if(selected(${d1},'2'),20,if(selected(${d1},'3'),30,if(selected(${d1},'4'),40,if(selected(${d1},'5'),50,if(selected(${d1},'6'),60,if(selected(${d1},'7'),70,if(selected(${d1},'8'),80,if(selected(${d1},'9'),90,if(selected(${d1},'10'),100,0))))))))))

I would also rather create one final note that would check the sum and then add one constraint there.
Please check this edited form:
GMLGhana_test.xlsx (10.1 KB)

Thanks so much @Grzesiek2010 ! Works like a charm.
Just for me to understand the logic behind though, why do I have to add ${sum} in the calculation column in the final note for this to work?

oh it's a trick because constraint is evaluated only if a question where it is used has non null value even if it doesn't check that value but the result of a previous question like in your case. I know it's confusing and long time ago I even reported it as an issue: https://github.com/getodk/javarosa/issues/327 but there hasn't been any interest in changing that behavior.

Ah, I see. Yeah it took me a few hours last night to figure out that constraint generally doesn't work on a "note" row....until you put in this trick. Thanks so much again!