I have a large file of several hundred thousand polygons. It's too many to have an individual colour, so I want to create a column of numbers to which I can assign a random colour. So how do I create a column in the attribute of numbers 1 to 50 on repeat?

1 Answer 1


If you want a number going from 1 to 50 and repeat, you can use the modulo % operator combined with the @id variable (older versions of QGIS can use $id instead) :

@id % 50 + 1

(the color can be directly randomized with QGIS expressions but that is not the OP question)


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.