Filling a field with automatic numbering specific by unique value of another field with QGIS expression

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite












I have a table with 2 fields: NUMBER (integer) and TOWN (text).
I would like to find an expression that fills the NUMBER field with an automatic number specific for each value of TOWN.
Example:
NUMBER | TOWN

----------------------

1 | STRASBOURG

2 | STRASBOURG

3 | STRASBOURG

1 | PARIS

2 | PARIS

1 | TOULOUSE

2 | TOULOUSE

3 | TOULOUSE

4 | TOULOUSE

How can I do that with a QGIS expression ?










share|improve this question

























    up vote
    1
    down vote

    favorite












    I have a table with 2 fields: NUMBER (integer) and TOWN (text).
    I would like to find an expression that fills the NUMBER field with an automatic number specific for each value of TOWN.
    Example:
    NUMBER | TOWN

    ----------------------

    1 | STRASBOURG

    2 | STRASBOURG

    3 | STRASBOURG

    1 | PARIS

    2 | PARIS

    1 | TOULOUSE

    2 | TOULOUSE

    3 | TOULOUSE

    4 | TOULOUSE

    How can I do that with a QGIS expression ?










    share|improve this question























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      I have a table with 2 fields: NUMBER (integer) and TOWN (text).
      I would like to find an expression that fills the NUMBER field with an automatic number specific for each value of TOWN.
      Example:
      NUMBER | TOWN

      ----------------------

      1 | STRASBOURG

      2 | STRASBOURG

      3 | STRASBOURG

      1 | PARIS

      2 | PARIS

      1 | TOULOUSE

      2 | TOULOUSE

      3 | TOULOUSE

      4 | TOULOUSE

      How can I do that with a QGIS expression ?










      share|improve this question













      I have a table with 2 fields: NUMBER (integer) and TOWN (text).
      I would like to find an expression that fills the NUMBER field with an automatic number specific for each value of TOWN.
      Example:
      NUMBER | TOWN

      ----------------------

      1 | STRASBOURG

      2 | STRASBOURG

      3 | STRASBOURG

      1 | PARIS

      2 | PARIS

      1 | TOULOUSE

      2 | TOULOUSE

      3 | TOULOUSE

      4 | TOULOUSE

      How can I do that with a QGIS expression ?







      qgis expression






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Etienne

      854




      854




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          3
          down vote













          Finally, I found the right expression to do that:



          "TOWN" ||( @row_number - minimum( @row_number , "TOWN") +1)





          share|improve this answer






















            Your Answer







            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "79"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            convertImagesToLinks: false,
            noModals: false,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













             

            draft saved


            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f299975%2ffilling-a-field-with-automatic-numbering-specific-by-unique-value-of-another-fie%23new-answer', 'question_page');

            );

            Post as a guest






























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes








            up vote
            3
            down vote













            Finally, I found the right expression to do that:



            "TOWN" ||( @row_number - minimum( @row_number , "TOWN") +1)





            share|improve this answer


























              up vote
              3
              down vote













              Finally, I found the right expression to do that:



              "TOWN" ||( @row_number - minimum( @row_number , "TOWN") +1)





              share|improve this answer
























                up vote
                3
                down vote










                up vote
                3
                down vote









                Finally, I found the right expression to do that:



                "TOWN" ||( @row_number - minimum( @row_number , "TOWN") +1)





                share|improve this answer














                Finally, I found the right expression to do that:



                "TOWN" ||( @row_number - minimum( @row_number , "TOWN") +1)






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 10 mins ago









                ahmadhanb

                19.5k21846




                19.5k21846










                answered 24 mins ago









                Etienne

                854




                854



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f299975%2ffilling-a-field-with-automatic-numbering-specific-by-unique-value-of-another-fie%23new-answer', 'question_page');

                    );

                    Post as a guest













































































                    Comments

                    Popular posts from this blog

                    What does second last employer means? [closed]

                    List of Gilmore Girls characters

                    Confectionery