Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

sum up default values of hidden questions

  • AlrikStelling
  • AlrikStelling's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 6 months ago #189502 by AlrikStelling
sum up default values of hidden questions was created by AlrikStelling
Survey is about hours spent per product. Products shown depends on chosen department. Department X has products UB1 and UB2, department Y has products UB3 and UB4. Defaults answer values are all set to 0.

User can only enter input for products of chosen department. So, if department Y is chosen the user will only be asked to enter hours spent on products UB3 and UB4, and cannot enter hours for UB1 nor UB2.

I want to create a single generic "total hours spent" formula, like total: {UB1+UB2+UB3+UB4}. This one failed. Apparently default values of hidden questions are NULL. That's fine.

Then I tried: total: {if(is_null(UB1,0,UB1)+if(is_null(UB2),0,UB2)+if(is_null(UB3),0,UB3)+if(is_null(UB4),0,UB4)}

This fails as well?? What should the general formula look like?
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 6 months ago - 4 years 6 months ago #189504 by DenisChenu
Replied by DenisChenu on topic sum up default values of hidden questions
manual.limesurvey.org/Expression_Manager#Usage_of_NAOK

sum(UB1.NAOK,UB2.NAOK,UB3.NAOK,UB4.NAOK) seems the best

Note, for consistency between JavaScript and PHP, the plus operator (+) does addition if both operands are numeric, but does concatenation if both parts are non-numeric strings. However, we recommend using the join() function for concatenation, as that makes your intent more clear, and avoids unexpected results if you were expecting strings but got numbers instead (or vice versa).

manual.limesurvey.org/Expression_Manager...s_operator_.28.2B.29

I put a subtile to give the link more easy on forum :)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Last edit: 4 years 6 months ago by DenisChenu. Reason: quote
The following user(s) said Thank You: tpartner, AlrikStelling
The topic has been locked.
  • AlrikStelling
  • AlrikStelling's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 6 months ago #189510 by AlrikStelling
Replied by AlrikStelling on topic sum up default values of hidden questions
Thanks for your very quick reply. This formula works indeed!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose