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.
-
1This 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– Joseph2018年06月15日 09:32:42 +00:00Commented Jun 15, 2018 at 9:32
1 Answer 1
Processing " Statistic by category" enter image description here
Join by attibute enter image description here
Result:
-
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– user397902018年06月15日 07:19:55 +00:00Commented Jun 15, 2018 at 7:19