how to use expressions manager to sum answers of arrays (text)

More
2 months 2 weeks ago - 2 months 2 weeks ago #173246 by mikebb
mikebb created the topic: how to use expressions manager to sum answers of arrays (text)
Hi
I'm trying the get my survey to calculate and save to the db subscale scores and totals.
I can get expressions manager to add the answer values from an array (5 point choice) question, eg:
{sum(question1_SQ001.value, question1_SQ002.value)}

This will show and save the answer to the db. the question type where the expression is entered is equation

But when the question type is a general array and the answer values are numeric (1,2,3..) the same expression won't calculate. I don't see a way to force the question to be considered as 'numbers only'.
I need a general array as the answers are categories with text descriptions (not just numbers, or yes/no..)

So... how do I do expressions maths on the array (general type) questions?

thanks!
Last Edit: 2 months 2 weeks ago by mikebb. Reason: clarity

Please Log in or Create an account to join the conversation.

More
2 months 2 weeks ago #173250 by mikebb
mikebb replied the topic: how to use expressions manager to sum answers of arrays (text)
OK i think i just found my answer. when the array's answer option codes are numeric (1,2,3..) then use:
{sum(question1_SQ001.code, question1_SQ002.code)}

.. yes?

Please Log in or Create an account to join the conversation.

More
2 months 2 weeks ago #173251 by Joffm
Joffm replied the topic: how to use expressions manager to sum answers of arrays (text)
Yes, and furthermore you can use the "that" variable.
https://manual.limesurvey.org/Expression_Manager_-_presentation#The_reserved_.22this.22.2C_.22self.22.2C_and_.22that.22_variables

{sum(that.question1.NAOK)}

Joffm


Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: mikebb

Please Log in or Create an account to join the conversation.

More
2 months 2 weeks ago #173258 by tpartner
tpartner replied the topic: how to use expressions manager to sum answers of arrays (text)
I don't understand why you can not use the assessment values and qCode.value in a normal array. If I assign assessment values, this works for me:

{sum(Q1_SQ001.value, Q1_SQ002.value, Q1_SQ003.value, Q1_SQ004.value)}



Sample survey attached:

File Attachment:

File Name: limesurvey...30-2.lss
File Size:26 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: mikebb

Please Log in or Create an account to join the conversation.

More
2 months 2 weeks ago #173282 by mikebb
mikebb replied the topic: how to use expressions manager to sum answers of arrays (text)
thanks for the replies - problem solved. LS is so feature rich I just don't understand all the options yet (ie assessments get me very confused).

cheers
Mike

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!