The problem as seen by the questioner will not have a solution of the expected kind (by a built-in tool of Calc).
Why?
Assuming the sheet intended to keep data, and to allow for their editing, mainenance, completion…
-1- Spreadsheets aren’t databases.
-2- If used for similar purposes nontheless, they should, however, obey the most basic DB rules.
-3- There are the so-called Normalizations e.g, in specific up to N3.
-4- Normalization may not be the main concern in this case.
But:
-5- Don’t tamper with the original data, except for urgent maintenance (corrections) and completion.
-6- Any direct manipulation (except mandatory correction or deletion) must be reversible.
-7- Sorting shouldn’t be done for the data themselves, but only for reports created from them.
-7a- If original data are sorted nonetheless, all fields (columns) must be included.
-7b- The autofilter context isn’t usable insofar.
-8- The concern of the question should be to find a design of the sheet supporting the intended proceeding.
-9- Empty cells in a field (column) are only acceptable where the being empty is an information in itself.
-10- “Group continues” is not such an information (probably except if the relative position is unchangeable).
-11- The mentioned information should (must) be given by repeating the group ID.
See attachment.
ask269629socalledAutofilterExampleReworked.ods