Hi
Similar questions (return > 1 match) have been asked and answered thousands of times on the community - and probably others…
With A2:B18 formatted as a Table (not mandatory, you can use a range as well) named tblInvoices:

in F2 (avoid re-calcs):
=COUNTIF(TableInvoices[Cust ID],F1)
in G1:
=IF(ROWS(F$1:F1)<=F$2, INDEX(TableInvoices[Invoice '#],AGGREGATE(15,6,(ROW(TableInvoices[Cust ID])-ROW(TableInvoices[#Headers]))/(TableInvoices[Cust ID]=F$1),ROWS(F$1:F1))),"")
and copy down as necessary
AGGREGATE function;
ROW function; ROWS function; INDEX function, COUNTIF function
Hope this helps