I have data with a column containing a number value, and I want to divide the value of each feature by the total sum of all the values in the column (to get a percentage).
So I would like to know if there is some simple syntax in the QGIS field calculator to get the sum of a column, preferably without resorting to for loops and what not.
I have a shapefile where feature A has the value X in column B. How can I summerize the values for all features in column B in order to divide value X to get a percentage for each feature?
Answer
Update: QGIS 2.18 (07/07/2017):
In the Field Calculator, you can use the Aggregate function sum
which allows you to sum the values of a column based on an expression. You can also, optionally, group and filter features for summation. So in your field calculator, you could simply use:
(sum( "column_B" ) / "column_B") * 100
Original post: 23/04/2015
You can't sum columns using the Field Calculator (although it would be useful in certain situations). To be able to sum columns and obtain a value, you can use:
- QGIS function - Basic Statistics (Vector > Analysis Tools > Basic Statistics)
- QGIS Plugin - GroupStats (Plugins > Manage and Install Plugins)
- QGIS Plugin - Statist (Plugins > Manage and Install Plugins)
So what I would do is create a new integer or real column (eg. "Sum") and add the value you obtain from any of the methods into the Expression window. Then create another column (eg. "Percentile") and edit the following expression to suit your column names:
("Sum" / "column_B") * 100
No comments:
Post a Comment