I assume your data is somewhere in your sheet, and I choose to start at B2.
If your original data is in B1:D6
For the first sort use this formula:
copy this formula to B8:D12
(it looks like the last two values in your 2nd example data are not in order, why?)
Attention: I'm using the first rows of the sheet for numbering, their values has not importance for the above formula. Wherever your data is, the
ROWS function should point the row number 1 with any column.
Now, for the unique values advance use this function:
copy this formula to B14:D18
Attention: I'm using the cell B7 and B13 knowing they are empty. Wherever you copy the system, the lines above the manipulated data better to be empty.