Using count-select () and if()

(Shawn) #1

I would like to use count-selected() and cond() to implement these instructions however my Xpath isn’t the best:

I know that the count-select() function requires 1 argument. But I need it to assign an integer base on the number of items selected. For example,

4 or 5 items = 1
2 or 3 items = 2
1 item = 3
0 items = 5

Is there another option?

Thanks

0 Likes

(Michel Akkaoui - de Sousa) #2

Hi,

Maybe you can try this :
cond(count-selected(guiding_question)=0, 5, count-selected(guiding_question)=1, 3, count-selected(guiding_question)=2, 2, count-selected(guiding_question)=3, 2, 1)

here some explanations :
https://wiki.commcarehq.org/display/commcarepublic/CommCare+Functions#CommCareFunctions-cond

-Michel

0 Likes

(Shawn) #3

Thanks Michael, I appreciate the expertise and the link. It worked perfectly. :relaxed:

0 Likes