4

With QGIS >=2.16, it is possible to use aggregates in expressions, such as sum, average... etc.

But when I use it to create a new virtual field using the field calculator, the newly created field value is null for all of the layer's entities.

An example here : field calc example

Am I doing it wrong ? Or it is a bug ?

I tried to change the field type with no effect. Note that it works when you create a non-virtual field.

5
  • 1
    I confirm that it does not work on with qgis 2.18 my computer either. You should probably file a bug report.
    – Victor
    Nov 8, 2016 at 11:06
  • I wanted to visually group features by some id by editing an attribute and have instant feedback on some aggregate value (e.g. sum of an attribute of features sharing the same group id). I came up with an alternative : having two layers in my project, a layer which target the postgis table I want to edit, and another one which is a view with the aggregates. I think there is a smarter way to do that but I know little about qgis.
    – tumasgiu
    Nov 15, 2016 at 9:42
  • I didn't know that qgis could edit postgresql views so only the view layer remains in my project now.
    – tumasgiu
    Nov 16, 2016 at 8:43
  • Did anyone submit a bug report/figure out a solution?
    – sid-kap
    Nov 15, 2017 at 2:53
  • The solution I've came up with is creating a view in db with triggers transmitting updates to the table, and editing that view in qgis. This is working only for RDBMS layers I guess. I wanted to fill a bug report, but I finally forgot to do that.
    – tumasgiu
    Nov 16, 2017 at 8:20

1 Answer 1

1

Fisrt, your field needs to be quoted.

Now look this example, the first one is to add the sum of all the field in each row; the second one, is to sum by row in a specific field.

You have Integer or Real (decimal number) to set your field, depending on what you need to get.

image

1
  • Hi, as I can say quoting is optional. And you're not creating a virtual field in your examples. I was aware that it would work the way you did. I'm looking to make it work with the "Create virtual field" box ticked. Thanks :)
    – tumasgiu
    Nov 7, 2016 at 14:27

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.