In QGIS 3 the Field calculator has a great function called @row_number (in QGIS 2 it was $rownum) which returns (assigns) the number of the current row.
Is there a way to make it work together with sorting?
Let's say I want to sort table by column "length" and get the order (sequence) of lines by length from shortest to longest.
I know I can use some office spreadsheet software easily for this to sort by column and populate new column with order (sequence). But I would prefer to do the whole job in QGIS.
As workaround there is also Changing order of features in shapefile - using MMQGIS Plugin and function modify/sort and after that use @row_number ($rownum) on the new saved file.


idcolumn (irrelevant, really), then I created a new columnorderwith sequential numbers (1-13) based on thenumfield (=ORDER_FIELDin the code). Then I sorted the table byorderto show thatnumhas been ordered as well. Your attribute table would almost always be sorted, if not by some field or combination of fields, then the underlying sequence of data in the file (which is the "default/original sorting", if you like - I think this order is accessed using$id). – she_weeds May 03 '20 at 21:54