Groupby include only counta < 4

Dave Patton

Well-known Member
Joined
Feb 15, 2002
Messages
6,485
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
I have a list of students and courses that is about 20000 rows. I need a list of students with less that x courses.
I included a small example that shows a list and the expected results (see D16:E19)
E


T202408b.xlsx
ABCDE
1StudentSubjectStudentStudent
2ABCArtAA2
3ABCEnglishABC5
4ABCScienceBBB4
5ABCHistoryCAA3
6ABCMath
7BBBArt
8BBBEnglish
9BBBScience
10BBBHistory
11CAAArt
12CAAEnglish
13CAAHistory
14AAMath
15AAArt
16Less than 4
17StudentStudent
18AA2
19CAA3
20
Sheet3
Cell Formulas
RangeFormula
D1:E5D1=GROUPBY(A1:A15,A1:A15,COUNTA,3,0)
Dynamic array formulas.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Power Query Solution

Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Grouped Rows" = Table.Group(Source, {"Student"}, {{"Count", each Table.RowCount(_), Int64.Type}}),
    #"Filtered Rows" = Table.SelectRows(#"Grouped Rows", each [Count] < 4)
in
    #"Filtered Rows"
 
Upvote 0
I don't have GroupBy yet on my MS365 build but wouldn't you just do this:
(Similar concept to Artik's version)

Excel Formula:
=LET(grp,GROUPBY(A1:A15,A1:A15,COUNTA,3,0),
            FILTER(grp,CHOOSECOLS(grp, 2)<4))
 
Upvote 0
Solution

Forum statistics

Threads
1,224,755
Messages
6,180,762
Members
452,996
Latest member
nelsonsix66

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