In Calc, can you lock the results of a formula to the row?

I am working with large spreadsheets (5000 rows x over 25 columns). After a sort, I need to tag rows into groups based on the row’s position in the sort. I can write a formula to assign each row a tag, but is there a way to make that tag “Stick” to the row after the next sort? All I have found is to manually re-enter the tag on each row, not practical with 5000 rows.

Maybe playing with the option Menu/Toools/Options/LibreOffice calc/General - Update references when sorting range of cells could help