You can try the following. Assuming no Excel version constraints as per the tags listed in the question.
=LET(A,A2:A7, B,B2:B7, C,C2:C7, ux,UNIQUE(A), cnts,COUNTIFS(A,A,B,B),
h,HSTACK("id", "item"&SEQUENCE(,ROWS(A)/ROWS(ux))),
REDUCE(h,ux,LAMBDA(ac,x,VSTACK(ac,
HSTACK(x,TOROW(SORTBY(FILTER(C,A=x),FILTER(cnts,A=x),-1)))))))
Here is the output:

h
name represents the header and cnts
, the counts of dates per id
.
We use REDUCE/VSTACK
pattern(1) to iterate over unique id column values. On each iteration, we use SORTBY
to sort C
by cnts
in reverse order filtering by id column values (A
) equal to x
, then we convert the result to a row-array via TOROW
and append it to x
via HSTACK
.
(1) Check my answer to the question: how to transform a table in Excel from vertical to horizontal but with different length.