Retaining an order when sorting by tags and filtering

I have a sorting requirement that I haven’t tackled before and I’m having a tough time getting my head around. This is probably best explained visually:

The “Master List” is a collection of pages that are all children of “Products”. Those pages have a tags field for sorting them in certain contexts. This is important, hence the numbers.

The “Grouped List” needs to group those pages by tag and then order them in a specific way. I had some success with this with group() but I need to “flip” the group order but not the pages themselves, the order should be retained.

I then also have a “filtered list” (which filters by the tags) where a mix of these pages can be shown but the master list number order should still be respected.

Any ideas how best to approach this?

You need to sort before grouping, then flip the group

1 Like

Thanks! I was struggling with this more than I should’ve been: two different groups were being created if the same tags were set but in a different order, so “tag 1, tag 2” and “tag 2, tag 1” were separate groups which was messing up my order when I flipped them.