Welcome to the LimeSurvey Community Forum

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

Filter based on counting - array by column

  • jantiend
  • jantiend's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
3 years 8 months ago #203382 by jantiend
Hi all, I'm building my first survey with limesurvey and this forum already has helped a lot, thank you! However, now I seem to want to do something that I haven't been able to find within this forum (not even something that looks alike). I puzzled a bit myself, but I have no clue where to start. I'm able to read and adjust existing code, but I have the feeling that I now need to write a code that's beyond my knowledge.

18 array by column questions: 2 columns with 6 answer options: most and least preferred (MaxDiff question).
In total there are 36 different answer options. Each answer option is displayed 3 times within these 18 questions, in different combinations.

19th question = use array filter to show the answer options that were most preferred within the 18 questions + the most preferred of a specific radiobox question that was asked in another group.

This 19th question may be on the same page as the 18 questions (same group), or be in a new group, whatever is easiest. Also, this 19th question may be a radiobox question instead of an array by column, if using an array by columns is too complicated.

This is what I was thinking of doing:
  1. Count the number of times each value is checked within the 'most' columns (td class = answer_cell_SQ001) of the 18 questions
  2. Show the values that were checked most (values range from 01 - 36)
  3. If there is a tie between 3 and 4 (and 5,6,7 etc): choose randomly between the answers with the tie

I've added a sample survey (with just a couple of sample questions, not the final design yet). I'm using version 3.22.26+200714.

Anyone who can help me, even if it's just pointing me in the right direction?



P.S. A small thing in the sample survey: once the last question is clicked, the survey scrolls to the top of the screen because there are no more question-container divs. I use a workaround by adding a hidden question on the bottom of the page, but maybe someone has a quick solution for this.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #203443 by holch
Replied by holch on topic Filter based on counting - array by column
For "building your first survey" you went all in on that one... ;-)

So from what I understand, you will fix theses combinations of 36 different options and not create them dynamically. This makes things easier I think.

19th question: You won't be able to use array filter here, because array filter would only work with one question, but not with the sum of the answers.

So you already went in the right direction of counting the number an item was checked. However, the maximum of the sum is 3. So you will probably have a lot of 3s and 2s, etc., which might make it difficult to distinguish between them.

Not sure what you mean with "If there is a tie between 3 and 4". Do you mean with the 3rd or 4th highest? As said above, I would expect a lot of "3s", depending on the options you are giving, of course.

What you could do is calculate the number of times an answer option was chosen via Expression Manager. That is probably actually the easy part, despite the expression probably being pretty long.

The problem is later to choose the highest scores. Not sure if this is possible with expression manager or if you would need to apply some Javascript as well.

I am sure that Tpartner will find a good solution and Joffm probably will also see this as a challenge. But I am sure that this will not be an easy solution. Should I find some time tonight, I also might give it a try, probably only partially, because JS is not my thing.

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

The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #203522 by Joffm
Replied by Joffm on topic Filter based on counting - array by column
Well, to accept @holch's challenge.

And of course it is a solution only using Expression Manager.
Javascript is Tony's part, EM mine.;)

It is easy to calculate the number of each item selected.
A hidden question of type "multiple numeric" ("MN") and a hidden question of type equation to calculate and fill the subquestions.

{MN_SQ001=countif("01",Q1_SQ001,Q2_SQ001,Q3_SQ001,Q4_SQ001,...)}{MN_SQ002=countif("02",Q1_SQ001,Q2_SQ001,Q3_SQ001,Q4_SQ001,...)}{MN_SQ003=countif("03",Q1_SQ001,Q2_SQ001,Q3_SQ001,Q4_SQ001,...)}
{MN_SQ004=countif("04",Q1_SQ001,Q2_SQ001,Q3_SQ001,Q4_SQ001,...)}
...

Now you know how many times item "XX" was selected "Meest".

Next equation ("eqMax1") to find the maximum:
{max(that.MN)}

Next equation:
Join all codes that match this maximum
{join(if(MN_SQ001==eqMax1,'A',''),if(MN_SQ002==eqMax1,'B',''),if(MN_SQ003==eqMax1,'C',''),if(MN_SQ004==eqMax1,'D',''),if(MN_SQ005==eqMax1,'E',''),if(MN_SQ006==eqMax1,'F',''),if(MN_SQ007==eqMax1,'G',''),if(MN_SQ008==eqMax1,'H',''),if(MN_SQ009==eqMax1,'I',''),if(MN_SQ010==eqMax1,'J',''),if(MN_SQ011==eqMax1,'K',''),if(MN_SQ012==eqMax1,'L',''))}

To have a randomization if there are ties, you may create a random number (1-2) and reverse this string (function "strrev) if randnumber==2.
To be able to do this I used letters.

Do the same for the second max and the third.
{max(if(MN_SQ001 lt eqMax1, MN_SQ001, 0), if(MN_SQ002 lt eqMax1, MN_SQ002, 0), if(MN_SQ003 lt eqMax1, MN_SQ003, 0), if(MN_SQ004 lt eqMax1, MN_SQ004, 0), if(MN_SQ005 lt eqMax1, MN_SQ005, 0), if(MN_SQ006 lt eqMax1, MN_SQ006, 0), if(MN_SQ007 lt eqMax1, MN_SQ007, 0), if(MN_SQ008 lt eqMax1, MN_SQ008, 0), if(MN_SQ009 lt eqMax1, MN_SQ009, 0), if(MN_SQ010 lt eqMax1, MN_SQ010, 0), if(MN_SQ011 lt eqMax1, MN_SQ011, 0), if(MN_SQ012 lt eqMax1, MN_SQ012, 0))}

Join all strings and use the first three letters to find your three most often selected items.

Later you will get an example.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 8 months ago #203527 by Joffm
Replied by Joffm on topic Filter based on counting - array by column
And here is the example.

I extended your four question to eight to have more material to test.
At the end you will find a multiple question that shows the most preferred three.

In this example no question is hidden.
Later all questions of group G2 should be hidden.

File Attachment:

File Name: limesurvey...891J.lss
File Size:90 KB


It's a long way with Expression Manager, but possible.
And in my opinion anybody without knowledge of javascript - like me - is able to do this.
Only with some ideas and using the implemented functions.

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose