At QGIS 3.8.2, I need to populate a field (let's call it field_a) in a sequentially increasing (1, 2, 3,...) order. However, I need the sequence to increase in the order that the table is currently sorted (let's say that it is currently sorted by field_b).

I tried @row_number, but the increasing sequence does not follow the current sort order. I think it follows an internal id, but I'm not sure...

  • test in the field calculator $id function, you can find it in therecord and attributes section of the field calculator Sep 6, 2019 at 19:24
  • @GerardoJimenez Thanks, but $id simply returns the value of the FID.
    – Stu Smith
    Sep 6, 2019 at 20:54
  • @she_weeds I've commented on your post.
    – Stu Smith
    May 3, 2020 at 16:29

1 Answer 1


Try the Sort and Number QGIS plugin, available in the Plugin Repository.

enter image description here


Sort and Number plugin


This plugin was coded in response to the recurrent issue of numbering a sorted attribute table, which has (currently) no simple workaround in QGIS. It creates a new field that contains the order of features, after sorting by up to 3 criteria.


First, select the vector layer you want to number. Then, select the fields you want to order. First field has priority on second field, which has priority on third field. Default order is ascending. Check the box next to a field to choose a descending order. Finally, enter the name of the numbering field to create. Default is 'order'.


v0.2: - added "sort only selected features" option (thanks to m4x300) - added i18n support (French translation)

v1.0: - compatibilty with QGIS 3.x (not compatible anymore with QGIS 2.x)

Not the answer you're looking for? Browse other questions tagged or ask your own question.