Using a series of Equation type questions in another calculation

More
4 years 10 months ago #84743 by tfj
tfj created the topic: Using a series of Equation type questions in another calculation
I have been struggling for the past couple of days on the syntax required for using a series of equation type questions for another calculation. I'm sure it is something simple and I am somewhat embarrassed to ask . . .

I have attached a sample survey to calculate the Addiction Severity Index for a series of questions related to Alcohol usage. On the second page of the survey, you will see some of the checks and various calculations I have tried. The first of the calculations works perfectly. (This is the one that says "The ASI for Alcohol Use = XXXX."

When I attempt an alternative calculation, however, in order to account for questions that may not have been answered, I get a concatenation, rather than an addition. I even ran checks on the equation questions to make sure they were numeric. This alternative calculation is based upon a series of previous equation questions.

I am using version 1.92+ build 120808.

Thanks!

tfj
Attachments:

Please Log in to join the conversation.

More
4 years 10 months ago #84745 by TMSWhite
TMSWhite replied the topic: Using a series of Equation type questions in another calculation
That might be a bug. The JavaScript portion of EM is supposed to concatenate strings, but add numbers when it sees the "+" sign.

I never ran into that myself because I always use the sum() function which will solve your immediate problem:

ASIAlcohol =
sum(alc30_1_1 / 180, Intox30_1_1 / 180, alcprob30_1_1 / 180, alctroub30 - 1 / 24, (alctximp - 1) / 24, LogAlcExp / 44)

ASIAlc2 =
sum(Alc30Calc, Intox30Calc, AlcProb30Calc, AlcTroub30Calc, AlcTxImpCalc, LogAlcExp / 44)

Please Log in to join the conversation.

More
4 years 10 months ago #84746 by tfj
tfj replied the topic: Using a series of Equation type questions in another calculation
Thank you for your help!

When I put the following for the question for ASIAlc2:

{sum(Alc30Calc, Intox30Calc, AlcProb30Calc, AlcTroub30Calc, AlcTxImpCalc, (LogAlcExp/44)}

I get the attached. I tried other combinations, but had no luck.

tfj
Attachments:

Please Log in to join the conversation.

More
4 years 10 months ago - 4 years 10 months ago #84748 by TMSWhite
TMSWhite replied the topic: Using a series of Equation type questions in another calculation
If you hover your mouse over the word sum (which is surrounded by a red box), it will tell you that you are missing a closing parenthesis.

You need either:
sum(Alc30Calc, Intox30Calc, AlcProb30Calc, AlcTroub30Calc, AlcTxImpCalc, LogAlcExp / 44)

or
sum(Alc30Calc, Intox30Calc, AlcProb30Calc, AlcTroub30Calc, AlcTxImpCalc, (LogAlcExp / 44))
Last Edit: 4 years 10 months ago by TMSWhite.

Please Log in to join the conversation.

More
4 years 10 months ago #84749 by tfj
tfj replied the topic: Using a series of Equation type questions in another calculation
Oops. Many thanks. It is interesting, though, how my two calculations, the original ASIAlc and the new ASIAlc2 don't quite match, but they are very close -- I'll do some more digging.

Thank you for your help . . . I totally forgot that hover part.

tfj

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now