Multiple question to count the numbers

More
2 months 3 weeks ago - 2 months 3 weeks ago #196989 by matthewpulis
I want to do a survey where for each question I give 2 options, but then I need to count how many K,A,E there are in the whole question group. Each question will be formed by two radio buttons and will have a code of K, A, E depending on the statement. Ultimately I need to count the total of Ks, As and Es chosen.


A working example is here: matthewbarr.co.uk/bartle/ - probably it's better if one views the source. I have done it in PHP: pastebin.com/sVASLzRz and now want to move it to LimeSurvey.

This is what I did:

I created a Question Group - 'test'
Created 3 questions/variables: explorer, achiever, killer.
Created 3 pairs of multiple choice questions T1, T2, T3.
The answer codes are 'A' and 'E' for T1.
I created another variable called result, and did this logic in it:
{if(T1.NAOK == "A", achiever.NAOK = sum(achiever.NAOK, 1), if(T1.NAOK == "E", explorer.NAOK = sum(explorer.NAOK, 1)))}

I did another expression which shows the results.
This is result:

results
t1: {T1.NAOK}
 
t2: {T2.NAOK}
 
t3: {T3.NAOK}
 
 
explorer {explorer.NAOK}
 
achiever {achiever.NAOK}
 
killer {killer.NAOK}


I am noticing that when I load the question explorer and achiever are already '2'.

The moment I choose an option, whatever the option, both increment by 2. Am flabbergasted as to why?


I am attaching the .lsg


Many thanks for your help!!
Attachments:
Last edit: 2 months 3 weeks ago by matthewpulis. Reason: forgot the {}

Please Log in to join the conversation.

LimeSurvey Partners
More
2 months 3 weeks ago #196994 by holch
Please always include an LSS file, not LSGs or LSQs.

For LSGs/LSQs the helpers in the forum need to create a survey to import it to, and hope that the base language of their survey is the same as the one in your files, because LSGs and LSQs are not language independent.

Also, the problem might be related to other settings in your survey, which the helpers won't notice, as they created a new survey with maybe different settings.

But please, do not just dump the whole survey, but only the parts that are relevant to your problem.

So please, copy your survey, delete all unnecessary overhead. Than check if the problem still persists (sometimes this already solves the problem and you need to check which other settings influence the problem). If the problem persists, the cleaned version as LSS and upload it here.

Help us to help you. Make it easy for us.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

Please Log in to join the conversation.

More
2 months 3 weeks ago #196997 by tpartner
I think you have the wrong syntax for your question assignment statements.

{qCode = if(condition, resultIfTrue, resultIfFalse)}

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com

Please Log in to join the conversation.

More
2 months 3 weeks ago #196998 by matthewpulis
Thanks for your reply holch.

Attached is the LSS. I created the Test survey where there is the test group for which I sent.

Many thanks
Attachments:

Please Log in to join the conversation.

More
2 months 3 weeks ago #196999 by matthewpulis
But since I am assigning different variables, how can I do that?

Thanks!

Please Log in to join the conversation.

More
2 months 3 weeks ago - 2 months 3 weeks ago #197001 by tpartner
You cannot assign variables in ExpressionScript in the normal way. All variables must be loaded into equation type questions, then you reference those question codes.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Last edit: 2 months 3 weeks ago by tpartner.

Please Log in to join the conversation.

More
2 months 3 weeks ago - 2 months 3 weeks ago #197002 by tpartner
ExpressionScript does not assign values to questions dynamically, it is only done on page load and page submit. Therefor you will need to move the report question to a different group.

Additionally, in your result question (which assigns values to explorer, achiever and killer) I think you want something like this:

{explorer = sum(if(T1 == 'E', 1, 0), if(T2 == '2E', 1, 0))}
{achiever = sum(if(T1 == 'A', 1, 0), if(T2 == '2A', 1, 0), if(T3 == '3A', 1, 0))}
{killer = if(T3 == '3K', 1, 0)}

Sample survey attached:

File Attachment:

File Name: limesurvey...5171.lss
File Size:22 KB



...but, why use assignments at all? Why not load explorer, achiever and killer directly?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Official LimeSurvey Partner - partnersurveys.com
Attachments:
Last edit: 2 months 3 weeks ago by tpartner.
The following user(s) said Thank You: matthewpulis

Please Log in to join the conversation.

More
2 months 3 weeks ago #197024 by matthewpulis
Tony,

Many thanks for your reply! That worked fine.

However, I'm afraid, I didn't understand your final suggestion: what do you mean load the variables directly?

I am understanding that from the working example which you sent me, I can save as part of the survey data, each of the answers and the computed answers of explorer, achiever, killer. Is that correct?

Once more many thanks for your help!!

Please Log in to join the conversation.

More
2 months 3 weeks ago - 2 months 3 weeks ago #197027 by Joffm
And if you use "better" codes in your answer options, you could do it easier.
If you - in all questions - code
achievers: 1
explorers: 2
killers: 3

you may use the implemented function "countifop"

achiever: {countifop("==",1,T1.NAOK,T2.NAOK,T3.NAOK)}

explorer: {countifop("==",2,T1.NAOK,T2.NAOK,T3.NAOK)}

killer: {countifop("==",3,T1.NAOK,T2.NAOK,T3.NAOK)}


Enter these equations in three questions of type equation as you have in your example at the start.

Joffm

Regarding your question: I think Tony wanted to explain, that it is not necessary to have these three equations at the start and later assign values to them.
Place these equations after your questions ent enter directly the formula, like
in equation "explorer"
{sum(if(T1 == 'E', 1, 0), if(T2 == '2E', 1, 0))}
in equation "achiever"
{sum(if(T1 == 'A', 1, 0), if(T2 == '2A', 1, 0), if(T3 == '3A', 1, 0))}


Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 months 3 weeks ago by Joffm.
The following user(s) said Thank You: matthewpulis

Please Log in to join the conversation.

More
2 months 3 weeks ago #197033 by matthewpulis
That is a much simpler way of doing it Joffm! Thanks loads!

Thanks for explaining what tonym said. Many many thanks to both of you. Will update the thread with the final implementation. Many thanks!

Please Log in to join the conversation.

More
2 months 3 weeks ago #197038 by matthewpulis
I'm uploading the final version of my test, just in case someone else would need it later.

JeffM's is the simplest way, especially when IRL case, you need a number of questions (this test IRL will be over 30 qs) - so it is much simpler.

Thanks everyone who contributed to this thread. Much appreciated!!
Attachments:

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now