Equations based on an Equation

More
3 years 3 months ago #119952 by jazzy
jazzy created the topic: Equations based on an Equation
Hello LimeSurvey World!

I have several arrays that I'm using equations to calculate their score. So let's say I have 3 arrays and the 3 equations, one equation after each array. This part works great! No Problems. But, can I use another equation to add them all up?

For instance the 3 equation fields are array1score, array2score, array3score. Can I have a last equation be the sum of the 3.

Total Score: {sum(array1score.value,array2score.value,array3score.value)}

So far it doesn't work for me. Keeps returning 0 even though each has a number showing. Wondering if the value isn't there until it's written to the database. I've also used the array1score.NAOK and it also didn't work.

Thanks for any help!

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

More
3 years 3 months ago #119954 by Bigred01
Bigred01 replied the topic: Equations based on an Equation
I just did a quick test and when i used .value on an array row, it always returned 0. Try using .NAOK, that worked for me.

In my working test I had 1 array and 3 equations. First equation had {array_1.NAOK}, second equation had {array_2.NAOK} and third had {sum(eq1.NAOK,eq2.NAOK)}.

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

More
3 years 3 months ago #119963 by jazzy
jazzy replied the topic: Equations based on an Equation
Thanks Bigred. I tried that but so far I feel like I'm just hitting my head against the wall and hoping for a different outcome :cheer:

I've attached a small sample survey to showcase my lack of understanding of this problem. If anyone can point me in the right direction to the promise land I would be much appreciative.

File Attachment:

File Name: array_test.lss
File Size:22 KB
Attachments:

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

More
3 years 3 months ago - 3 years 3 months ago #119964 by Bigred01
Bigred01 replied the topic: Equations based on an Equation
I don't think you can access the assessment value in the survey (someone please correct me if im wrong).

Here is an example of what you can do though.

{sum(if(array1_SQ001.NAOK == "4",-1,array1_SQ001.NAOK),if(array1_SQ002.NAOK == "4",-1,array1_SQ002.NAOK),if(array1_SQ003.NAOK == "4",-1,array1_SQ003.NAOK))}

Set the answer code to the number value you want. Of course we cant set a code to -1, but the if statement above will change a 4 into a -1 when summing your answers.

Also, you have text in your equations making them strings so you final sum wouldn't have worked.

Remove the text and modify the above sum/if statements for your first two equation questions then sum them together in your final equation question.

I attached an updated copy of the survey as well.
Attachments:
Last Edit: 3 years 3 months ago by Bigred01. Reason: sub to sum
The following user(s) said Thank You: jazzy

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

More
3 years 3 months ago #119968 by jazzy
jazzy replied the topic: Equations based on an Equation
You Rock! I was putting text in the fields and trying to do calculations with it. In my head I thought it was just saving everything after the colon and the before part was just for show.

Thank You!!

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!