简体   繁体   中英

Excel & GoogleSheets - Randbetween with condition

I have a table with entered numbers (A:A) and specific dates (B:B). How could I randomly choose between entered number for each specific date?

In attached example, F2 should be random value between each number in A:A where B:B = 13.12.2022

在此处输入图像描述

I've tried playing with index and randbetween, but no result. I need formula for both Excel and Google Sheets.

Update: for Excel these do the trick

=INDEX($A$1:$A$30;INDEX(LARGE(($B$1:$B$30=D2)*ROW($A$1:$A$30);ROW($A$1:$A$30));1+INT(RAND()*COUNTIF($B$1:$B$30;D2))))

=MAP(D2:D4,LAMBDA(a,LET(x,FILTER(A2:A11,B2:B11=a),@SORTBY(x,RANDARRAY(COUNT(x))))))

But this doesnt work for Google Sheets.

One option, try:

在此处输入图像描述

Formula in E2 :

=MAP(D2:D4,LAMBDA(a,INDEX(FILTER(A2:A11,B2:B11=a),RANDBETWEEN(1,COUNTIF(B:B,a)))))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM