Welcome to the LimeSurvey Community Forum

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

Randomly show one of the 2 values in a table in question text

  • bajpai
  • bajpai's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 10 months ago #217025 by bajpai
I have a table in question type - Array (numbers), that looks like below:
  .

There are 8 such tables questions in the group.
I have 8 random generator questions that each generate 2 unique random numbers between 1 and 4
 

then 8 group of 4 questions , out of which only 2 would be shown based on the 2 random numbers generated by R1, R2 ...R8
 

No I have to create another group called SP with 8 questions , that looks like below:
 

Here I have to divide randomly 4 times, the 2 values captured or filled by respondent in other 8 questions. i.e. if 2 random number generated by R1_SQ001 =2 and R! SQ002 =3 then the 2 statements below will be true{if(((R1_SQ001==2) OR (R1_SQ002==2)),(L42024PriceB_Q1_A1.shown, L42024PriceB_Q1_A2.shown,L42024PriceB_Q1_A3.shown,L42024PriceB_Q1_A4.shown,L42024PriceB_Q1_A5.shown))}{if(((R1_SQ001==3) OR (R1_SQ002==3)),(L42024PriceC_Q1_A1.shown, L42024PriceC_Q1_A2.shown,L42024PriceC_Q1_A3.shown,L42024PriceC_Q1_A4.shown,L42024PriceC_Q1_A5.shown))}

and the system should show the 2 selected values but shows nothing as of now:
  L42024PriceB_Q1_A1.shown, L42024PriceB_Q1_A2.shown,L42024PriceB_Q1_A3.shown,L42024PriceB_Q1_A4.shown,L42024PriceB_Q1_A5.shown)
 

Please find my survey attached here: 

File Attachment:

File Name: limesurvey...2461.lss
File Size:306 KB


Looking forward help and response!
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #217030 by Joffm
Though I have no idea what exactly you want to display in this cell (you should show an example what was entered in 42024PriceA and what is shown in SP),
this equation is wrong syntax
{if(((R1_SQ001==3) OR (R1_SQ002==3)),(L42024PriceC_Q1_A1.shown, L42024PriceC_Q1_A2.shown,L42024PriceC_Q1_A3.shown,L42024PriceC_Q1_A4.shown,L42024PriceC_Q1_A5.shown))}

And to extract the x-scale text from the entire property ".question" you may use this combination of functions
Probability of Vehicle Price (incl. VAT) relative to similar manual trucks[+30%]
{str_replace("]","",substr(L42024PriceA_Q1_A1.question,strpos(L42024PriceA_Q1_A1.question,"[")+1))}

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • bajpai
  • bajpai's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 10 months ago #217040 by bajpai
Dear Joffm,

Thank you so much for your reply above. Now I know how to extract sub question text from the entire question text with the above syntax you suggested.
following box colored in red - is what is to be shown in the text cell above in SP table. i.e. the fixed percentages written in subquestion text (+10%, +15%, +20%, 25%, +30 %) along with the values filled in by respondent. 
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago #217043 by Joffm
Hi,

a correct syntax would be (if you want to have a comma-separated list), 
{if(R1_SQ001==1 OR R1_SQ002==1,L42024PriceA_Q1_A1.shown+", "+ L42024PriceA_Q1_A2.shown+", "+L42024PriceA_Q1_A3.shown+", "+L42024PriceA_Q1_A4.shown+", "+L42024PriceA_Q1_A5.shown,"")}

This you could have got much easier by using the "list"-function:
{if(R1_SQ001==1 OR R1_SQ002==1,list(that.L42024PriceA.sq_Q1.shown))}


But I think you want to have something like this ( I said before, I have no idea)
 

Here the syntax is:
{if(R1_SQ001==1 OR R1_SQ002==1,
str_replace("]","",substr(L42024PriceA_Q1_A1.question,strpos(L42024PriceA_Q1_A1.question,"[")+1))+": "+L42024PriceA_Q1_A1.shown+"<br />"+
str_replace("]","",substr(L42024PriceA_Q1_A2.question,strpos(L42024PriceA_Q1_A2.question,"[")+1))+": "+L42024PriceA_Q1_A2.shown+"<br />"+
str_replace("]","",substr(L42024PriceA_Q1_A3.question,strpos(L42024PriceA_Q1_A3.question,"[")+1))+": "+L42024PriceA_Q1_A3.shown+"<br />"+
str_replace("]","",substr(L42024PriceA_Q1_A4.question,strpos(L42024PriceA_Q1_A4.question,"[")+1))+": "+L42024PriceA_Q1_A4.shown+"<br />"+
str_replace("]","",substr(L42024PriceA_Q1_A5.question,strpos(L42024PriceA_Q1_A5.question,"[")+1))+": "+L42024PriceA_Q1_A5.shown,"")}


only for this first case "R1_SQ001==1 OR R1_SQ002==1".

I recommend to calculate this in some equations before. Will simplify your table code a lot.

Joffm




 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The topic has been locked.
  • bajpai
  • bajpai's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
2 years 10 months ago #217048 by bajpai
Thank you much Joffm. This is exactly what I would need. And of course, it would be best to build a question before with 4 list options like below and display the ones that are applicable. Could you also suggest which question type would be the best to incorporate this?

1. L4 2024
a.
{if(R1_SQ001==1 OR R1_SQ002==1,
str_replace("]","",substr(L42024PriceA_Q1_A1.question,strpos(L42024PriceA_Q1_A1.question,"[")+1))+": "+L42024PriceA_Q1_A1.shown+"<br />"+
str_replace("]","",substr(L42024PriceA_Q1_A2.question,strpos(L42024PriceA_Q1_A2.question,"[")+1))+": "+L42024PriceA_Q1_A2.shown+"<br />"+
str_replace("]","",substr(L42024PriceA_Q1_A3.question,strpos(L42024PriceA_Q1_A3.question,"[")+1))+": "+L42024PriceA_Q1_A3.shown+"<br />"+
str_replace("]","",substr(L42024PriceA_Q1_A4.question,strpos(L42024PriceA_Q1_A4.question,"[")+1))+": "+L42024PriceA_Q1_A4.shown+"<br />"+
str_replace("]","",substr(L42024PriceA_Q1_A5.question,strpos(L42024PriceA_Q1_A5.question,"[")+1))+": "+L42024PriceA_Q1_A5.shown,"")}

b. 
{if(R1_SQ001==2 OR R1_SQ002==2,
str_replace("]","",substr(L42024PriceB_Q1_A1.question,strpos(L42024PriceB_Q1_A1.question,"[")+1))+": "+L42024PriceB_Q1_A1.shown+"<br />"+
str_replace("]","",substr(L42024PriceB_Q1_A2.question,strpos(L42024PriceB_Q1_A2.question,"[")+1))+": "+L42024PriceB_Q1_A2.shown+"<br />"+
str_replace("]","",substr(L42024PriceB_Q1_A3.question,strpos(L42024PriceB_Q1_A3.question,"[")+1))+": "+L42024PriceA_Q1_A3.shown+"<br />"+
str_replace("]","",substr(L42024PriceB_Q1_A4.question,strpos(L42024PriceB_Q1_A4.question,"[")+1))+": "+L42024PriceB_Q1_A4.shown+"<br />"+
str_replace("]","",substr(L42024PriceB_Q1_A5.question,strpos(L42024PriceB_Q1_A5.question,"[")+1))+": "+L42024PriceB_Q1_A5.shown,"")}

c. 
{if(R1_SQ001==3 OR R1_SQ002==3,
str_replace("]","",substr(L42024PriceC_Q1_A1.question,strpos(L42024PriceC_Q1_A1.question,"[")+1))+": "+L42024PriceC_Q1_A1.shown+"<br />"+
str_replace("]","",substr(L42024PriceC_Q1_A2.question,strpos(L42024PriceC_Q1_A2.question,"[")+1))+": "+L42024PriceC_Q1_A2.shown+"<br />"+
str_replace("]","",substr(L42024PriceC_Q1_A3.question,strpos(L42024PriceC_Q1_A3.question,"[")+1))+": "+L42024PriceC_Q1_A3.shown+"<br />"+
str_replace("]","",substr(L42024PriceC_Q1_A4.question,strpos(L42024PriceC_Q1_A4.question,"[")+1))+": "+L42024PriceC_Q1_A4.shown+"<br />"+
str_replace("]","",substr(L42024PriceC_Q1_A5.question,strpos(L42024PriceC_Q1_A5.question,"[")+1))+": "+L42024PriceC_Q1_A5.shown,"")}

d. R1_SQ002 == 4
{if(R1_SQ001==4 OR R1_SQ002==4,
str_replace("]","",substr(L42024PriceD_Q1_A1.question,strpos(L42024PriceC_Q1_A1.question,"[")+1))+": "+L42024PriceC_Q1_A1.shown+"<br />"+
str_replace("]","",substr(L42024PriceD_Q1_A2.question,strpos(L42024PriceD_Q1_A2.question,"[")+1))+": "+L42024PriceD_Q1_A2.shown+"<br />"+
str_replace("]","",substr(L42024PriceD_Q1_A3.question,strpos(L42024PriceD_Q1_A3.question,"[")+1))+": "+L42024PriceD_Q1_A3.shown+"<br />"+
str_replace("]","",substr(L42024PriceD_Q1_A4.question,strpos(L42024PriceD_Q1_A4.question,"[")+1))+": "+L42024PriceD_Q1_A4.shown+"<br />"+
str_replace("]","",substr(L42024PriceD_Q1_A5.question,strpos(L42024PriceD_Q1_A5.question,"[")+1))+": "+L42024PriceD_Q1_A5.shown,"")}
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago - 2 years 10 months ago #217051 by Joffm
As I wrote

"in some equations before".

That is question of type "equation".

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 years 10 months ago by Joffm.
The topic has been locked.
  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
2 years 10 months ago - 2 years 10 months ago #217060 by Joffm
One last remark.

This construct is absolutely obsolete in your survey
{str_replace("]","",substr(L42024PriceA_Q1_A1.question,strpos(L42024PriceA_Q1_A1.question,"[")+1))}
because the x-scale options of each question are fixed,

Therefore it is sufficient to hard code them. Or do you plan something dynamically, like "micro-tayloring" in the questions?
And this is all:
I repeated the IF-stement to make it more obvious. Orf course you can concatenate with "+".
<p>
{if(R1_SQ001==1 OR R1_SQ002==1,"+10%: "+L42024PriceA_Q1_A1.shown+"<br />","")}
{if(R1_SQ001==1 OR R1_SQ002==1,"+15%: "+L42024PriceA_Q1_A2.shown+"<br />","")}
{if(R1_SQ001==1 OR R1_SQ002==1,"+20%: "+L42024PriceA_Q1_A3.shown+"<br />","")}
{if(R1_SQ001==1 OR R1_SQ002==1,"+25%: "+L42024PriceA_Q1_A4.shown+"<br />","")}
{if(R1_SQ001==1 OR R1_SQ002==1,"+30%: "+L42024PriceA_Q1_A5.shown+"<br />","")}
</p>
<p>
{if(R1_SQ001==2 OR R1_SQ002==2,"+10%: "+L42024PriceB_Q1_A1.shown+"<br />","")}
{if(R1_SQ001==2 OR R1_SQ002==2,"+15%: "+L42024PriceB_Q1_A2.shown+"<br />","")}
{if(R1_SQ001==2 OR R1_SQ002==2,"+20%: "+L42024PriceB_Q1_A3.shown+"<br />","")}
{if(R1_SQ001==2 OR R1_SQ002==2,"+25%: "+L42024PriceB_Q1_A4.shown+"<br />","")}
{if(R1_SQ001==2 OR R1_SQ002==2,"+30%: "+L42024PriceB_Q1_A5.shown+"<br />","")}
</p>
<p>
{if(R1_SQ001==3 OR R1_SQ002==3,"+10%: "+L42024PriceC_Q1_A1.shown+"<br />","")}
{if(R1_SQ001==3 OR R1_SQ002==3,"+15%: "+L42024PriceC_Q1_A2.shown+"<br />","")}
{if(R1_SQ001==3 OR R1_SQ002==3,"+20%: "+L42024PriceC_Q1_A3.shown+"<br />","")}
{if(R1_SQ001==3 OR R1_SQ002==3,"+25%: "+L42024PriceC_Q1_A4.shown+"<br />","")}
{if(R1_SQ001==3 OR R1_SQ002==3,"+30%: "+L42024PriceC_Q1_A5.shown+"<br />","")}
</p>
<p>
{if(R1_SQ001==4 OR R1_SQ002==4,"+10%: "+L42024PriceD_Q1_A1.shown+"<br />","")}
{if(R1_SQ001==4 OR R1_SQ002==4,"+15%: "+L42024PriceD_Q1_A2.shown+"<br />","")}
{if(R1_SQ001==4 OR R1_SQ002==4,"+20%: "+L42024PriceD_Q1_A3.shown+"<br />","")}
{if(R1_SQ001==4 OR R1_SQ002==4,"+25%: "+L42024PriceD_Q1_A4.shown+"<br />","")}
{if(R1_SQ001==4 OR R1_SQ002==4,"+30%: "+L42024PriceD_Q1_A5.shown+"<br />","")}
</p>


and so on for the other cells.

 

In my opinion missing: A header in this cell to show which question it was.
And: Wouldn't it be sufficient to display the value with the highest probability?

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 2 years 10 months ago by Joffm.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose