Saturday 20 July 2019

field calculator - Expression string builder QGIS


I created a virtual field in my layer where I want a specific value to be calculated. In my attribute table I have several columns. The expression I am trying to create is the following. I want to iterate through all features and add all values of the column age who have a specific value, let's say the name of the features should be marc. In my first attempt I created this:


CASE WHEN  "name"  = "marc" THEN  sum(  "age" ) END

But it kinda doesn't work and I don't know how to iterate though all features in the layer and only choose those features with the name marc. Any advice?




Answer



You could use something like the following:


sum( "age", "name", "name" = 'marc' )



Where:



  • "age" is the field used to calculate the sum;

  • "name" is the field used to group the different names together;

  • "name" = 'marc' is the expression used to filter all names in the name field which equal marc.



No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...