Is there a way to number a subset of entries in the attribute table based on the current sorting in Qgis? e.g. select all entries with attribute X, sort them by abttribute Y, create a new column and fill the column (only for the selected and sorted values) whith 1 to n; not rownum or id.

  • I had to do the same but I just had to sort it by one ID and there were just two different values - so I copied it to a temporary table and then inserted it, so it was sorted and I could use $rownum. There is also an approach with using Calc gis.stackexchange.com/a/41506/24484 but for me it didn't work.
    – meles
    Commented Feb 5, 2016 at 10:38

1 Answer 1


I guess you might have a solution in QGIS 3.2 with a new feature added, thanks to Nyall Dawson (North Road). I haven't tried, but i guess oyou could try filtering the layer before running this new tool ?

Feature: Sort order option for "Add Incremental Field"

This change allows users to optionally set a sort order to use when assigning values in the Add Incremental Field algorithm. Previously values were always added using the original feature order. With this change users can control the order in which features are assigned values.

  • 1
    works like a charme, was exactly what i needed. particularly the "group values by" to define ordered groups! thanks!
    – user16032
    Commented Feb 6, 2019 at 9:52
  • Happy to know it helped ! Thanks for your detailed comment on your usage.
    – gisnside
    Commented Feb 6, 2019 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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