Given that there are only two "tables" this is manageable using this proposed method.
The 'helper' column, which may be moved and/or hidden for aesthetic purposes, displays all sub dept's in department 1 using:
Formula:
=IFERROR(INDEX(B$1:B$10,AGGREGATE(15,6,ROW($1:$10)/(A$1:A$10=A$1),ROW(1:1))),INDEX(E$1:E$10,AGGREGATE(15,6,ROW($1:$10)/(D$1:D$10=A$1),ROW(1:1)-COUNTIFS(A$1:A$10,A$1))))
The 'final' column displays sorted unique values using*:
Formula:
=IFERROR(INDEX(I$2:I$20,MATCH(SUM(COUNTIF(J$1:J1,I$2:I$20)),COUNTIF(I$2:I$20,"<"&I$2:I$20),0)),"")
*Denotes an array entered formula which is confirmed by pressing CTRL+SHIFT+ENTER to activate the array, not just ENTER. You will know the array is active when you see curly braces { } appear around your formula. If you do not CTRL+SHIFT+ENTER you will get an error or a clearly incorrect answer.
Let us know if you have any questions.
Bookmarks