admin管理员组

文章数量:1242841

I have the following sheet

My goal is to return data in col P randomly from col N or from col O. If cell B3 contains "2 shifts", it should return from col N and if cell B3 contains "3 shifts", it should return from col O. The amount of random cells to be returned is in D3 and should be able to be changed as wanted. I can extract cells in order by using the below.

=ArrayFormula(QUERY({N2:N, RANDARRAY(ROWS(N2:N))}, "SELECT Col1 LIMIT "&$D3))

The above only returns the first 6 but only contains 1 criteria. I cannot make it work. Please help PS: I can only use formulas and not scripts.

I have the following sheet

My goal is to return data in col P randomly from col N or from col O. If cell B3 contains "2 shifts", it should return from col N and if cell B3 contains "3 shifts", it should return from col O. The amount of random cells to be returned is in D3 and should be able to be changed as wanted. I can extract cells in order by using the below.

=ArrayFormula(QUERY({N2:N, RANDARRAY(ROWS(N2:N))}, "SELECT Col1 LIMIT "&$D3))

The above only returns the first 6 but only contains 1 criteria. I cannot make it work. Please help PS: I can only use formulas and not scripts.

Share Improve this question edited 11 hours ago Patsytalk 9751 gold badge1 silver badge15 bronze badges asked Feb 17 at 12:36 JeromeJerome 738 bronze badges 2
  • Please do not upload images of code/data/errors. – TheMaster Commented Feb 17 at 15:39
  • Make sure to provide input and expected output as plain text table in the question. Check my answer or other options to create a table easily, which are easy to copy/paste. Avoid sharing links like spreadsheets, which make the question useless for others or images, which are hard to copy. Also, note that your email address can also be accessed by the public, if you share Google files. – TheMaster Commented Feb 17 at 15:39
Add a comment  | 

1 Answer 1

Reset to default 1

Try:

=LET(
  arr, TOCOL({IF(B3 = "2 shifts", N2:N, O2:O)}, 1),
  SORTN(arr, D3, , RANDARRAY(ROWS(arr)), )
 )

本文标签: google sheetsExtract randomly data according to multiple criteriaStack Overflow