Welcome to the LimeSurvey Community Forum

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

Randomly select X out of Y groups with filter

  • elissa
  • elissa's Avatar Topic Author
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 hours 23 minutes ago - 5 hours 22 minutes ago #270769 by elissa
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.14.3
Own server or LimeSurvey hosting: Own
Survey theme/template: Fruity
==================

Hello Team,

I’m looking for a solution to the following issue:In the first multiple-answer question, respondents select the products they use: A, B, C, D, E, and F. Based on their selections, they are then asked detailed follow-up questions grouped by each product (groups A to F).However, I need to limit the number of follow-up groups shown for products A to D. Specifically:
  • If a respondent selects one or two products from A, B, C, or D, they should see the corresponding one or two follow-up groups.
  • If they select three or four products from A–D, they should be shown only two of these follow-up groups (randomly).
  • All respondents who select E and/or F should always see the corresponding follow-up groups E and/or F.
I'll be grateful for you help.Thank you!

Elzbieta Lesinska
LS voluntary Polish translator and supervisor
Last edit: 5 hours 22 minutes ago by elissa.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
53 minutes ago #270770 by Joffm
Hi,
here my usual solution without javascript.
Create an equation and a "container" (C), a question of type "multiple short text" 

In the equation enter the following:
  • Fill B1 (something like "Base1") with characters referring to the selected subquestions
    {C_B1=join(if(Q01_1=="Y","A",""),if(Q01_2=="Y","B",""),if(Q01_3=="Y","C",""),if(Q01_4=="Y","D",""))}
  • Generate a random number (1 - length of this string)
    {C_R1=rand(1,strlen(C_B1))}
  • Store the character at this place
    {C_S1=substr(C_B1,C_R1-1,1)}
  • Remove the selected character to get the new base
    {C_B2=str_replace(C_S1,"",C_B1)}
  • Generate a random number (1 - length of this string)
    {C_R2=rand(1,strlen(C_B2))}
  • Store the character at this place
    {C_S2=substr(C_B2,C_R2-1,1)}
  • Join both selected characters  and the characters that refer to E and F
    {C_tot=join('#',C_S1,C_S2,if(Q01_5=="Y","E",""),if(Q01_6=="Y","F",""))}

Now you display the following groups if the total string containds the character
strpos(C_tot,"A")>0

The survey:
 

File Attachment:

File Name: limesurvey...88_J.lss
File Size:73 KB


Joffm

 

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