I'm using QGIS and I need an expression to change an attribute each X number of rows. For instance I have the next attribute data:

enter image description here

I want to create an attribute (C) that assigns an ordered value each 3 rows. With the next result:

enter image description here

1 Answer 1


Assuming your rows are already sorted, you just have to create a new integer field with the expression: ($rownum + 1) / 3

  • Thanks a lot. That was exactly what I needed and I didn't figure it out :-( Aug 29, 2017 at 12:09

Your Answer

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

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