Problem description & analysis:
In the Excel table below, column A is the grouping field and column B contains detail data.
A | B | |
1 | Group | Name |
2 | A | John |
3 | A | Joe |
4 | A | Ann |
5 | A | Susan |
6 | A | James |
7 | A | Mary |
8 | A | L .orraine |
9 | B | Joseph |
10 | B | Sinead |
11 | B | Michelle |
12 | B | Breege |
13 | B | Tom |
14 | B | Francis |
15 | B | Conan |
16 | B | Cait |
17 | B | Ronan |
18 | B | Deirdre |
19 | B | Aoife |
20 | B | Sile |
21 | B | Sarah |
22 | C | Lisa |
23 | C | Micky |
24 | C | Pat |
25 | D | Miles |
26 | D | Olivia |
27 | D | Avril |
28 | D | Conor |
29 | D | Jane |
30 | D | Robyn |
31 | D | June |
We want to get a row from each group randomly.
E | F | |
1 | Group | Name |
2 | A | Mary |
3 | B | Sarah |
4 | C | Micky |
5 | D | Miles |
Solution:
Use SPL XLL to do this:
=spl("=E(?).sort(rand()).group@1(Group)",A1:B31)
As shown in the picture below:
Explanation:
E()function parses the range as a table. sort(rand()) arranges rows randomly. group@1 groups rows and gets the 1st record from each group.
For more related information, please download SPL XLL for free:
SPL download address: esProc Desktop Download
Plugin Installation Method: SPL XLL Installation and Configuration
References to other rich Excel operation cases: Desktop and Excel Data Processing Cases
SPL Programming (YouTube FREE courses): https://www.youtube.com/playlist?list=PLQeR-IhHo7qNCw6o7PW8YfHvRx8pgzZso