I've an attribute column named e.g. VALUE with different values I would like to make a column named e.g. ORDERsuch that the greatest value has the attribute 1 the second value 2 etc. etc. so order express the order from the biggest to the smallest value like this:

12000     1
8000      2
600       3
500       4
200       5

So far I've tried with QGIS 1.8 to order the VALUE column (that please note is not in the right order by default) from maxto minsimply clicking over the attribute name and than use $rownumin field calculator but this seems use the default rows numeration so I don't have the right order.

Please edit my question if you think you can explain it better!

  • Which data source are you using?
    – Rui Lima
    Dec 31, 2013 at 14:16
  • @RuiLima I've got the data directly form the vector layers in fact they are position of point of vector layers I've made... But it was to difficult to explain in question
    – G M
    Dec 31, 2013 at 14:22
  • I would suggest you to use the console a write a very simple Python script. I am not with QGis right now, later I might try to help you with that.
    – Rui Lima
    Dec 31, 2013 at 14:30
  • @RuiLima thanks a lot I will try something in the mean while...
    – G M
    Dec 31, 2013 at 14:32

2 Answers 2


Here's a funny trick using a Spatialite query to get the values in descending order. If you do a count() and use a WHERE clause to get values >= the current value, then you'll actually be getting the order, so if I have a table "mypoints" with a column "value" and an empty column of "value_order" then:

SELECT value, (
SELECT count(*) FROM mypoints AS my 
WHERE my.value>=mypoints.value) AS orders
FROM mypoints 

gives a list of the values and their order. I can then update the "value_order" column like so:

UPDATE mypoints SET val_order = (
SELECT count(*) FROM mypoints AS my 
WHERE my.value>=mypoints.value



I guess you could first create a new, sorted layer (How to permanently rearrange the order of features in a Shapfile with QGIS?) and then use Field calculator $rownum.

  • mmm seems is the only alternative for the moment... thanks!
    – G M
    Dec 31, 2013 at 14:26

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.