Hey,
i have a select multiple question with 9 choices ('b.1' - 'b.9') and
if the user didn't choose 'b.1', the calculation will show: 0%
or if the user choose 'b.1' , and more 3 choices the calculation will show: 30%
or if the user choose 'b.1' , and more 5 choices the calculation will show: 60%
or if the user choose 'b.1' , and more 7 choices the calculation will show: 90%
or if the user choose 'b.1' , and all other choices the calculation will show: 100%.
i wrote it this way and the odk validate is not accepting it, what's the problem?
<if((not (selected(${pediatric.services1},'b.1'))),0%,if((selected(${pediatric.services1},'b.1') and (${calculate.pediatric.services1}<=4)),30%,if((selected(${pediatric.services1},'b.1') and (${calculate.pediatric.services1}=5)),60%,if((selected(${pediatric.services1},'b.1') and (${calculate.pediatric.services1}=6)),60%,if((selected(${pediatric.services1},'b.1') and (7<=${calculate.pediatric.services1}<=9)),90%,if((selected(${pediatric.services1},'b.1') and (${calculate.pediatric.services1}=9)),100%,0))))))>
Hi @Khaled_Altaher
could you attach your form it's always easier to help then than analyzing raw expressions.
1 Like
It probably doesn't like that you are trying to result a value of 0%
- this should probably be quoted; ie '0%'
, but there's a bunch of other things wrong too... 
Also, its probably worth pointing out that you can significantly simplify your calculation (hence fewer chance of error) by observing the fact that checking for (selected(${pediatric.services1},'b.1')
everywhere else is redundant, because by that point in the calculation it must have been selected, otherwise the initial if((not(selected(${pediatric.services1},'b.1')))...
would have picked it up!
Try something more like this [I'm having to somewhat interpret your desired intended ranges here...]:
if(not(selected(${pediatric_services1},'b.1')),'0%', if(count-selected(${pediatric_services1})<=3, '30%', if(count-selected(${pediatric_services1})<=6, '60%', if(count-selected(${pediatric_services1})<=9, '90%', '100%'))))
1 Like
THANK YOU @Xiphware!
It worked very well 
1 Like
Hi @Khaled_Altaher,
Thanks for the feedback, remember to close the thread by marking the solution above.
1 Like
Glad it worked for you, and hope I wasn’t too far off the mark with your desired ranges... 
2 Likes