Welcome to the LimeSurvey Community Forum

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

Matrix (Text): Sum up one column of all rows

  • dknfoenfojn
  • dknfoenfojn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 months 2 weeks ago #265748 by dknfoenfojn
Please help us help you and fill where relevant:
Your LimeSurvey version: LimeSurvey Community Edition Version 6.5.15+240701 
Own server or LimeSurvey hosting:  own Server
Survey theme/template: fruity_twentythreee
==================

Hello,

i am new to LimeSurvey and i am absolutely stunned how feature rich its. :)

I've one question i couldn't solve by myself yet:
I have a question of the type Matrix (text) with 10 rows and 3 columns.
The first two columns of one row is text and the last one is a numerical value. For background: The participants should name a product in column 1 and write something about it in column 2 and in column 3 the value of the product should be named in euro. e.g for row 1 (called Product 1): Newspaper (column 1), Getting news (column 2), 3 (column 3).

Now i want to add up every row and calculate column 3 of all rows.
I've tried:
{SQ003_SQ013+SQ007_SQ013} but it states "unknown variable".

Is this even possible?

Thank you :)
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 2 weeks ago #265749 by Joffm
Hi,
I assume
"SQ003" and "SQ007" refer to two y-axis subquestions
"SQ013" is the code of your third column, the third x-axis subquestion.

Now, as you read here in the manual
[url] www.limesurvey.org/manual/ExpressionScri...code_variable_naming [/url]
The QCode consists of  "QuestionCode . '_' . SubQuestionID . '_' . ScaleId
So in your equation the question code is missing.
If you are not sure about it, activate your survey and have a look at the responses table.
Afterwards you deactivate it.

Should be something like this:
{Q1_SQ003_SQ013.NAOK+Q1_SQ007_SQ013.NAOK}
Now the improvements:
You should use the "sum" function to  consider this
[url] www.limesurvey.org/manual/ExpressionScri...ntation/en#Operators [/url]
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. It also avoids unexpected results if you were expecting strings but got numbers instead (or vice versa).
In some (rare) cases 14+23=1423

So better
{sum(Q1_SQ003_SQ013.NAOK,Q1_SQ007_SQ013.NAOK)}

I personally prefer to code the x-axis and y-axis differently to avoid confusion
If you code the y-axis "Y001", "Y002", ... and the x-axis "X001" "X002",...
you can use the "self" and "that variables.
[url] www.limesurvey.org/manual/ExpressionScri...%22that%22_variables [/url]
To sum up all values of column 3 in an equation
{sum(that.sq_X003.NAOK)}

If I misunderstood please send the lss export of the survey (these relevant questions)

Joffm

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

Please Log in to join the conversation.

  • dknfoenfojn
  • dknfoenfojn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 months 2 weeks ago - 3 months 2 weeks ago #265761 by dknfoenfojn
Replied by dknfoenfojn on topic Matrix (Text): Sum up one column of all rows
Thank you very much, Joffm! It works like a charm! :) I am really impressed. And i've already learned so much. 

I have one more questions about concatenation. I want to sum up two values from two columns within two questions:
{sum(that.G07Q07.sq_SQ013.NAOK) + sum(that.G07Q09.sq_SQ013.NAOK)}

But the value is always wrong because it's handled like a string? So I have the sum for question 1 column 3 = 15 and questions 2 column 3 = 20. 
The above equation is 1520.

Is there anything i can do to avoid that?

And a bonus questions: I'f the sum of both columns 3 (question 1 + question 2) is > 15000 it is not possible to continue. Is this also doable?
Last edit: 3 months 2 weeks ago by dknfoenfojn.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 1 week ago #265763 by Joffm
Hi,
{sum(that.G07Q07.sq_SQ013.NAOK) + sum(that.G07Q09.sq_SQ013.NAOK)}
either
{sum(that.G07Q07.sq_SQ013.NAOK,that.G07Q09.sq_SQ013.NAOK)}
or
{sum(sum(that.G07Q07.sq_SQ013.NAOK),sum(that.G07Q09.sq_SQ013.NAOK))}

Send the lss export in the future.

Joffm

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

Please Log in to join the conversation.

  • dknfoenfojn
  • dknfoenfojn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 months 1 week ago #265828 by dknfoenfojn
Replied by dknfoenfojn on topic Matrix (Text): Sum up one column of all rows
Thank you very much! It works now :)

How can I achieve the following:

If the value of {sum(sum(that.G07Q07.sq_SQ013.NAOK),sum(that.G07Q09.sq_SQ013.NAOK))} is bigger than 15000 the survey can't be continued and the values have to be corrected.

I already figured out {sum(sum(that.G07Q07.sq_SQ013.NAOK),sum(that.G07Q09.sq_SQ013.NAOK)) <= 15000}

but the survey can be continued normally. Even when the value is higher than 15000.

I've added the *.lsg of the corresponding group. Thank you :) 

File Attachment:

File Name: limesurvey...p_12.lsg
File Size:40 KB

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 1 week ago #265833 by Joffm
Please, neither provide lsq nor lsq files, only lss.

{sum(sum(that.G07Q07.sq_SQ013.NAOK),sum(that.G07Q09.sq_SQ013.NAOK)) <= 15000}
Where did you enter this?
In the question validation equation?
It is wrong syntax. Here you do not surround with curly brackets.

And I do not understand why you do this double sum? I know I mentioned it as an option.
But it is simple arithmetic: (A+B) + (C+D) = A+B+C+D
sum(that.G07Q07.sq_SQ013.NAOK,that.G07Q09.sq_SQ013.NAOK) <= 15000

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

Please Log in to join the conversation.

  • dknfoenfojn
  • dknfoenfojn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 months 1 week ago #265839 by dknfoenfojn
Replied by dknfoenfojn on topic Matrix (Text): Sum up one column of all rows
Thank you again for your time and help! :)

I've made a invisible question of the type Equation and put 

sum(that.G07Q07.sq_SQ013.NAOK,that.G07Q09.sq_SQ013.NAOK) <= 15000 

into the condition field.

This time i have upload the .lss file. Sorry for uploading the wrong file last time.

Maybe you can help me and show me how to do it the correct way? :) Thank you!
 

File Attachment:

File Name: limesurvey...5234.lss
File Size:116 KB

Please Log in to join the conversation.

  • dknfoenfojn
  • dknfoenfojn's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 months 1 week ago #265861 by dknfoenfojn
Replied by dknfoenfojn on topic Matrix (Text): Sum up one column of all rows
Hello again :)

I just wanted to ask if someone has a solution or a hint for me to solve this problem.

I have achieved now that a text is displayed if the sum is =>15000. but the Survey can still be continued to the next page. The Survey should Not end completely but the user has to correct the values so that the sum is =<15000.

I hope someone can help me :) thank you!

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 months 1 week ago #265872 by Joffm
Yes, you did this

into the condition field.

The condition manages if a question is displayed or not. Something quite different.

You want to do a question validation.
So this belongs in the question validation equation - preferable in both
And a meaningful validation tip and eveything is nearly fine.
 

Maybe some improvements
You should consider
  • "Dynamic" display of rows
  • Display the subtotals right in the question text
  • If you want to store the subtotals just use a hidden equation
 



You find this in my "Tutorial 1: Matrizen" in the German section, page 11,12,...

Joffm

P.S.
Why didn't you use the still existing script to calculate the sums?
Now I am tired to write English without necessity.

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose