Random Selection of Data

Ghost141

New Member
Joined
Dec 7, 2023
Messages
12
Office Version
  1. 365
Platform
  1. Windows
Hi gang, not sure if its even possible with excel formula or VBA but worth a shot. Im looking at being able to pull a series of random data from a list consisting of 4 columns.

The "randomiser" would pull up to 5 random lines per name and all of the line if they have less than 5.

I have provided an example output to help explain.

Thanks so much.

Book4
ABCDEFGHI
1IDDateNameTypeExpected OutputIDDateNameType
212345674/19/24Mr ABlack12345684/20/24Mr APink
312345684/20/24Mr APink12345694/21/24Mr ABlue
412345694/21/24Mr ABlue12345704/22/24Mr ARed
512345704/22/24Mr ARed12345724/24/24Mr ABlack
612345714/23/24Mr ARed12345674/19/24Mr ABlack
712345724/24/24Mr ABlack12345734/25/24Mr BPink
812345734/25/24Mr BPink12345744/19/24Mr BBlue
912345744/19/24Mr BBlue12345754/20/24Mr BRed
1012345754/20/24Mr BRed12345784/23/24Mr CRed
1112345764/21/24Mr CRed12345804/25/24Mr CBlue
1212345774/22/24Mr CPink12345824/20/24Mr CRed
1312345784/23/24Mr CRed12345844/22/24Mr CBlue
1412345794/24/24Mr CPink12345854/23/24Mr CBlack
1512345804/25/24Mr CBlue12345874/25/24Mr DBlue
1612345814/19/24Mr CRed12345884/19/24Mr DRed
1712345824/20/24Mr CRed12345894/20/24Mr DRed
1812345834/21/24Mr CPink12345914/22/24Mr DRed
1912345844/22/24Mr CBlue12345924/23/24Mr DPink
2012345854/23/24Mr CBlack12345934/24/24Mr EBlue
2112345864/24/24Mr CPink12345944/25/24Mr ERed
2212345874/25/24Mr DBlue12345954/19/24Mr ERed
2312345884/19/24Mr DRed12345974/21/24Mr FBlue
2412345894/20/24Mr DRed12345984/22/24Mr FPink
2512345904/21/24Mr DPink12346004/24/24Mr FRed
2612345914/22/24Mr DRed12346024/19/24Mr FBlue
2712345924/23/24Mr DPink12346034/20/24Mr FRed
2812345934/24/24Mr EBlue12346064/23/24Mr GBlue
2912345944/25/24Mr ERed12346074/24/24Mr GRed
3012345954/19/24Mr ERed12346084/25/24Mr GBlue
3112345964/20/24Mr FPink
3212345974/21/24Mr FBlue
3312345984/22/24Mr FPink
3412345994/23/24Mr FPink
3512346004/24/24Mr FRed
3612346014/25/24Mr FPink
3712346024/19/24Mr FBlue
3812346034/20/24Mr FRed
3912346044/21/24Mr FRed
4012346054/22/24Mr FPink
4112346064/23/24Mr GBlue
4212346074/24/24Mr GRed
4312346084/25/24Mr GBlue
Sheet1
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
See if this power query solution works for you.

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Name"}, {{"Count", each _, type table [ID=number, Date=number, Name=text, Type=text]}}),
    #"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.AddIndexColumn([Count],"Index",1,1)),
    #"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Count"}),
    #"Expanded Custom" = Table.ExpandTableColumn(#"Removed Columns", "Custom", {"ID", "Date", "Type", "Index"}, {"ID", "Date", "Type", "Index"}),
    #"Filtered Rows" = Table.SelectRows(#"Expanded Custom", each [Index] < 6),
    #"Removed Columns1" = Table.RemoveColumns(#"Filtered Rows",{"Index"})
in
    #"Removed Columns1"
 
Upvote 0
With a formula
Fluff.xlsm
ABCDEFGHI
1IDDateNameTypeExpected OutputIDDateNameType
2123456719/04/2024Mr ABlack123457224/04/2024Mr ABlack
3123456820/04/2024Mr APink123457123/04/2024Mr ARed
4123456921/04/2024Mr ABlue123457022/04/2024Mr ARed
5123457022/04/2024Mr ARed123456820/04/2024Mr APink
6123457123/04/2024Mr ARed123456921/04/2024Mr ABlue
7123457224/04/2024Mr ABlack123457419/04/2024Mr BBlue
8123457325/04/2024Mr BPink123457520/04/2024Mr BRed
9123457419/04/2024Mr BBlue123457325/04/2024Mr BPink
10123457520/04/2024Mr BRed123458220/04/2024Mr CRed
11123457621/04/2024Mr CRed123458422/04/2024Mr CBlue
12123457722/04/2024Mr CPink123458321/04/2024Mr CPink
13123457823/04/2024Mr CRed123457621/04/2024Mr CRed
14123457924/04/2024Mr CPink123457823/04/2024Mr CRed
15123458025/04/2024Mr CBlue123458725/04/2024Mr DBlue
16123458119/04/2024Mr CRed123458920/04/2024Mr DRed
17123458220/04/2024Mr CRed123459223/04/2024Mr DPink
18123458321/04/2024Mr CPink123459122/04/2024Mr DRed
19123458422/04/2024Mr CBlue123458819/04/2024Mr DRed
20123458523/04/2024Mr CBlack123459324/04/2024Mr EBlue
21123458624/04/2024Mr CPink123459425/04/2024Mr ERed
22123458725/04/2024Mr DBlue123459519/04/2024Mr ERed
23123458819/04/2024Mr DRed123460125/04/2024Mr FPink
24123458920/04/2024Mr DRed123460522/04/2024Mr FPink
25123459021/04/2024Mr DPink123459923/04/2024Mr FPink
26123459122/04/2024Mr DRed123460024/04/2024Mr FRed
27123459223/04/2024Mr DPink123459721/04/2024Mr FBlue
28123459324/04/2024Mr EBlue123460825/04/2024Mr GBlue
29123459425/04/2024Mr ERed123460724/04/2024Mr GRed
30123459519/04/2024Mr ERed123460623/04/2024Mr GBlue
31123459620/04/2024Mr FPink
32123459721/04/2024Mr FBlue
33123459822/04/2024Mr FPink
34123459923/04/2024Mr FPink
35123460024/04/2024Mr FRed
36123460125/04/2024Mr FPink
37123460219/04/2024Mr FBlue
38123460320/04/2024Mr FRed
39123460421/04/2024Mr FRed
40123460522/04/2024Mr FPink
41123460623/04/2024Mr GBlue
42123460724/04/2024Mr GRed
43123460825/04/2024Mr GBlue
Sheet5
Cell Formulas
RangeFormula
F1:I30F1=REDUCE(A1:D1,UNIQUE(TOCOL(C2:C100,1)),LAMBDA(x,y,VSTACK(x,LET(f,FILTER(A2:D100,C2:C100=y),TAKE(SORTBY(f,RANDARRAY(ROWS(f))),5)))))
Dynamic array formulas.
 
Last edited:
Upvote 0
With a formula
Fluff.xlsm
ABCDEFGHI
1IDDateNameTypeExpected OutputIDDateNameType
2123456719/04/2024Mr ABlack123457224/04/2024Mr ABlack
3123456820/04/2024Mr APink123457123/04/2024Mr ARed
4123456921/04/2024Mr ABlue123457022/04/2024Mr ARed
5123457022/04/2024Mr ARed123456820/04/2024Mr APink
6123457123/04/2024Mr ARed123456921/04/2024Mr ABlue
7123457224/04/2024Mr ABlack123457419/04/2024Mr BBlue
8123457325/04/2024Mr BPink123457520/04/2024Mr BRed
9123457419/04/2024Mr BBlue123457325/04/2024Mr BPink
10123457520/04/2024Mr BRed123458220/04/2024Mr CRed
11123457621/04/2024Mr CRed123458422/04/2024Mr CBlue
12123457722/04/2024Mr CPink123458321/04/2024Mr CPink
13123457823/04/2024Mr CRed123457621/04/2024Mr CRed
14123457924/04/2024Mr CPink123457823/04/2024Mr CRed
15123458025/04/2024Mr CBlue123458725/04/2024Mr DBlue
16123458119/04/2024Mr CRed123458920/04/2024Mr DRed
17123458220/04/2024Mr CRed123459223/04/2024Mr DPink
18123458321/04/2024Mr CPink123459122/04/2024Mr DRed
19123458422/04/2024Mr CBlue123458819/04/2024Mr DRed
20123458523/04/2024Mr CBlack123459324/04/2024Mr EBlue
21123458624/04/2024Mr CPink123459425/04/2024Mr ERed
22123458725/04/2024Mr DBlue123459519/04/2024Mr ERed
23123458819/04/2024Mr DRed123460125/04/2024Mr FPink
24123458920/04/2024Mr DRed123460522/04/2024Mr FPink
25123459021/04/2024Mr DPink123459923/04/2024Mr FPink
26123459122/04/2024Mr DRed123460024/04/2024Mr FRed
27123459223/04/2024Mr DPink123459721/04/2024Mr FBlue
28123459324/04/2024Mr EBlue123460825/04/2024Mr GBlue
29123459425/04/2024Mr ERed123460724/04/2024Mr GRed
30123459519/04/2024Mr ERed123460623/04/2024Mr GBlue
31123459620/04/2024Mr FPink
32123459721/04/2024Mr FBlue
33123459822/04/2024Mr FPink
34123459923/04/2024Mr FPink
35123460024/04/2024Mr FRed
36123460125/04/2024Mr FPink
37123460219/04/2024Mr FBlue
38123460320/04/2024Mr FRed
39123460421/04/2024Mr FRed
40123460522/04/2024Mr FPink
41123460623/04/2024Mr GBlue
42123460724/04/2024Mr GRed
43123460825/04/2024Mr GBlue
Sheet5
Cell Formulas
RangeFormula
F1:I30F1=REDUCE(A1:D1,UNIQUE(TOCOL(C2:C100,1)),LAMBDA(x,y,VSTACK(x,LET(f,FILTER(A2:D100,C2:C100=y),TAKE(SORTBY(f,RANDARRAY(ROWS(f))),5)))))
Dynamic array formulas.
Incredible, thanks so much!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,348
Messages
6,124,423
Members
449,157
Latest member
mytux

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top