Is there a way to use the field calculator in QGIS to create a range of values in a count sequence with a specified input range? For example, if I wanted to have the values 1 to 5 repeated within my table according to the first record in the table.


  • Do you want to fill in 1,2,3,4,5,1,2,3,4,5,... or values dependent on another attribute?
    – underdark
    Nov 19, 2012 at 16:11
  • Yes Underdark, that is what I want. 1,2,3,4,5 until all records are calculated. Nov 19, 2012 at 16:16

2 Answers 2


This will do it in Field Calculator:

 ( $rownum-1 ) % 5 +1

enter image description here

  • 2
    I love seeing stuff like this, and figured out some of the stuff by myself. But where can I find a more comprehensive documentation of all the things possible with the Field Calculator?
    – SAnderka
    Nov 19, 2012 at 17:10
  • @SAnderka The new field calculator comes with a long list of documented functions - all visible in the GUI. Possibilities are near endless :)
    – underdark
    Nov 19, 2012 at 17:12
  • I know, but somehow I am missing some basics here, I believe. What exactly does the "%5+1" part do? Also, my copy of QGIS (installed and updated via OSGEO4W) only shows "Oops! QGIS can't find help for this function." in the help window?
    – SAnderka
    Nov 19, 2012 at 17:16
  • % is the modulo operator - like in many computer languages. It returns the remainder of the devision (by 5 in this case). On my OSGeo4W system docs are broken in 1.8 too but work fine in dev1.9.
    – underdark
    Nov 19, 2012 at 17:21
  • Ah, I'm still on 1.8.0_4, that might be the reason. And I'll have to look more into programming languages, it seems... sigh
    – SAnderka
    Nov 19, 2012 at 18:25

My solution for this kind of problem is to use Libre or OpenOffice Calc. First of all check if your FID column is intact and correct (you'll need it to restore the attribute file to its original order if you resort the dbf table in Calc - otherwise the features will have the wrong data attached afterwards).

Create a Backup of the dbf, just in case.

Then, just open the dbf-file in Calc (don't forget to use the right codepage setting when opening the file, otherwise you might lose umlauts etc.), do whatever you want to do, e.g. autofill a column with data via vlookup(), and save the file again as dbf.

Check the result in QGIS, but everything should work just fine now.

  • Thank you, I know of this approach, but I wanted a means of doing this within QGIS. Nov 19, 2012 at 15:23
  • Also, I misunderstood your question - I thought you were looking for a way to add values depending on a changing other variable (not that I would have known the way to do this within QGIS... :))
    – SAnderka
    Nov 19, 2012 at 17:12

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.