Multiplying values for each field with unique id











up vote
1
down vote

favorite












For one country I have




  • population densities (highlighted with a red rectangular) per watershed

  • literacy rate 4.48% (highlighted with a green rectangular)

  • watershed IDs, e.g. 3222, 3271 etc.


I'd like to multiply the population of each watershed by literacy rate. Is there a way to do so?



Perhaps using the field calculator?



Data_sample










share|improve this question




























    up vote
    1
    down vote

    favorite












    For one country I have




    • population densities (highlighted with a red rectangular) per watershed

    • literacy rate 4.48% (highlighted with a green rectangular)

    • watershed IDs, e.g. 3222, 3271 etc.


    I'd like to multiply the population of each watershed by literacy rate. Is there a way to do so?



    Perhaps using the field calculator?



    Data_sample










    share|improve this question


























      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      For one country I have




      • population densities (highlighted with a red rectangular) per watershed

      • literacy rate 4.48% (highlighted with a green rectangular)

      • watershed IDs, e.g. 3222, 3271 etc.


      I'd like to multiply the population of each watershed by literacy rate. Is there a way to do so?



      Perhaps using the field calculator?



      Data_sample










      share|improve this question















      For one country I have




      • population densities (highlighted with a red rectangular) per watershed

      • literacy rate 4.48% (highlighted with a green rectangular)

      • watershed IDs, e.g. 3222, 3271 etc.


      I'd like to multiply the population of each watershed by literacy rate. Is there a way to do so?



      Perhaps using the field calculator?



      Data_sample







      qgis field-calculator attribute-table






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 26 at 9:47









      Taras

      1,5922522




      1,5922522










      asked Nov 26 at 8:14









      Guillaume

      1065




      1065






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:



          to_real(replace("Rate_text", ',','.'))


          Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :



          "Pop"*"Rate_Num" 


          enter image description here






          share|improve this answer






























            up vote
            2
            down vote













            My suggestion is to deploy a Virtual layer through




            Layer > Add layer > Edit/Add Virtual Layer




            Please try the following statements in the query field





            If you need values for fields that share the same id



            SELECT SUM(population_densities*literacy_rate)
            FROM your_layer
            GROUP BY watershed_number
            ORDER BY watershed_number




            If you need values for each single field



            SELECT population_densities*literacy_rate
            FROM your_layer
            ORDER BY watershed_number




            References:




            • Virtual layers

            • SQL GROUP BY Statement






            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: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: null,
              bindNavPrevention: true,
              postfix: "",
              imageUploader: {
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              },
              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%2f303894%2fmultiplying-values-for-each-field-with-unique-id%23new-answer', 'question_page');
              }
              );

              Post as a guest















              Required, but never shown

























              2 Answers
              2






              active

              oldest

              votes








              2 Answers
              2






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes








              up vote
              1
              down vote



              accepted










              You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:



              to_real(replace("Rate_text", ',','.'))


              Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :



              "Pop"*"Rate_Num" 


              enter image description here






              share|improve this answer



























                up vote
                1
                down vote



                accepted










                You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:



                to_real(replace("Rate_text", ',','.'))


                Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :



                "Pop"*"Rate_Num" 


                enter image description here






                share|improve this answer

























                  up vote
                  1
                  down vote



                  accepted







                  up vote
                  1
                  down vote



                  accepted






                  You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:



                  to_real(replace("Rate_text", ',','.'))


                  Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :



                  "Pop"*"Rate_Num" 


                  enter image description here






                  share|improve this answer














                  You need to convert your literacy rate text to real in order to do the calculation. The rate 4,48 is of text type, thus, you need to convert it to real type to become 4.48 as number not as text. To do that, create a new field of type real (decimal) and name it "Rate_Num" for example, and under "Rate_Num" write the following expression to convert the rate text into rate number:



                  to_real(replace("Rate_text", ',','.'))


                  Then add a new field of type real (decimal) to calculate the population density and multiply the "Population" field with the "Rate_Num" field using the following formula, in this example the new field name is "Result", :



                  "Pop"*"Rate_Num" 


                  enter image description here







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 30 at 5:27

























                  answered Nov 26 at 8:43









                  ahmadhanb

                  21.1k31850




                  21.1k31850
























                      up vote
                      2
                      down vote













                      My suggestion is to deploy a Virtual layer through




                      Layer > Add layer > Edit/Add Virtual Layer




                      Please try the following statements in the query field





                      If you need values for fields that share the same id



                      SELECT SUM(population_densities*literacy_rate)
                      FROM your_layer
                      GROUP BY watershed_number
                      ORDER BY watershed_number




                      If you need values for each single field



                      SELECT population_densities*literacy_rate
                      FROM your_layer
                      ORDER BY watershed_number




                      References:




                      • Virtual layers

                      • SQL GROUP BY Statement






                      share|improve this answer



























                        up vote
                        2
                        down vote













                        My suggestion is to deploy a Virtual layer through




                        Layer > Add layer > Edit/Add Virtual Layer




                        Please try the following statements in the query field





                        If you need values for fields that share the same id



                        SELECT SUM(population_densities*literacy_rate)
                        FROM your_layer
                        GROUP BY watershed_number
                        ORDER BY watershed_number




                        If you need values for each single field



                        SELECT population_densities*literacy_rate
                        FROM your_layer
                        ORDER BY watershed_number




                        References:




                        • Virtual layers

                        • SQL GROUP BY Statement






                        share|improve this answer

























                          up vote
                          2
                          down vote










                          up vote
                          2
                          down vote









                          My suggestion is to deploy a Virtual layer through




                          Layer > Add layer > Edit/Add Virtual Layer




                          Please try the following statements in the query field





                          If you need values for fields that share the same id



                          SELECT SUM(population_densities*literacy_rate)
                          FROM your_layer
                          GROUP BY watershed_number
                          ORDER BY watershed_number




                          If you need values for each single field



                          SELECT population_densities*literacy_rate
                          FROM your_layer
                          ORDER BY watershed_number




                          References:




                          • Virtual layers

                          • SQL GROUP BY Statement






                          share|improve this answer














                          My suggestion is to deploy a Virtual layer through




                          Layer > Add layer > Edit/Add Virtual Layer




                          Please try the following statements in the query field





                          If you need values for fields that share the same id



                          SELECT SUM(population_densities*literacy_rate)
                          FROM your_layer
                          GROUP BY watershed_number
                          ORDER BY watershed_number




                          If you need values for each single field



                          SELECT population_densities*literacy_rate
                          FROM your_layer
                          ORDER BY watershed_number




                          References:




                          • Virtual layers

                          • SQL GROUP BY Statement







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 27 at 6:59

























                          answered Nov 26 at 8:38









                          Taras

                          1,5922522




                          1,5922522






























                              draft saved

                              draft discarded




















































                              Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid



                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.


                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function () {
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f303894%2fmultiplying-values-for-each-field-with-unique-id%23new-answer', 'question_page');
                              }
                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                              Mangá

                              Eduardo VII do Reino Unido