Reputation: 27
Im new to google apps script and need some help So I have a list of questions of multiple types and I want to pick a specific number of questions of a certain type. My spreadsheet formatting is like this.
A1 = questionID (Q1, Q2 ,Q3)
B1 = questionType (1, 2, 3)
D1 = number of questions required
E1 = type of question required
I can already shuffle the questions to make it randomized, but that requires 2 steps. Is it possible to picking random questions of a type at the same time?
Upvotes: 1
Views: 65
Reputation: 4034
This is possible with Sheet formulas and no scripting.
=query(
sort(Source!$A$2:$B, arrayFormula(randbetween(sign(row(Source!$A$2:$B)), 1000000)), true),
"select Col1, Col2
where Col1!='' AND Col2="&$E$1&"
limit "&$E$2&"", 0)
The 3 lines within the Query are:
E1
and limit the returned responses to the number in E2
I have amended your example workbook with a sheet that demonstrates this.
Upvotes: 1