2

Can anyone help me parse an aggregate function for Qgis 2.18 which sums the values of one field, for all entries which match a value of the entry in question.

So, for example if I have a simple layer with field "group", and "value", and entries are;

Group,Value

1,3

1,4

1,5

2,3

2,5

2,6

I want an expression which will yield "Group Total" such that,

Group,Value,Group Total

1,3,12

1,4,12

1,5,12

2,3,14

2,5,14

2,6,14

Next to all the entries in group 1 is the sum of all group 1, next to all the entries in group 2 is the sum of group 2

EDIT - I should add I've tried the most obvious sum("Value", "Group"), the predicted output in the expression calculator shows correct, but in the table the values are all just NULL, so I presume I'm doing something wrong.

EDIT2 - I should also have added that I'm looking for this function to automatically update somehow, in a virtual field, otherwise every time some value changes in my layer (and things do change!) all the totals will be wrong.

  • 1
    This issue has been reported but still seems to be a problem with some QGIS 2.18 versions. It works with QGIS 3.x however. – Joseph Jun 15 '18 at 9:32
2
  1. Processing " Statistic by category" enter image description here

  2. Join by attibute enter image description here

Result:

enter image description here

  • Thank you for your suggestion, but I'm actually looking for a field which will automatically update, like virtual fields, so I don't think creating a new layer from it will work. I should have been clearer in the question, and have now edited it. – user39790 Jun 15 '18 at 7:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy