Add cumulative sum column to attribute tableHow to add a new column in attribute table with attribute with...
Translation for threshold (figuratively)
How do I split ammo?
When distributing a Linux kernel driver as source code, what's the difference between Proprietary and GPL license?
Aligning Systems of Equations
Are there any spells or magic items that allow for making of ‘logic gates or wires’?
How do I know my password or backup information is not being shared when creating a new wallet?
Multiple null checks in Java 8
How can a kingdom keep the secret of a missing monarch from the public?
What does @ mean in a hostname in DNS configuration?
TikZtree with asymmetric siblings
The Longest Chess Game
How do I handle a blinded enemy which wants to attack someone it's sure is there?
Why are `&array` and `array` pointing to the same address?
Why is airport car rental so cheap
80-bit collision resistence because of 80-bit x87 registers?
Can I do anything else with aspersions other than cast them?
Empty optional argument or Not giving optional argument at all?
Taking an academic pseudonym?
Is it ethical to apply for a job on someone's behalf?
Smallest possible mole
How do I add a strong "onion flavor" to the biryani (in restaurant style)?
How can changes in personality/values of a person who turned into a vampire be explained?
Is opening /proc/meminfo faster than reading variable content?
How many copper coins fit inside a cubic foot?
Add cumulative sum column to attribute table
How to add a new column in attribute table with attribute with indexes of another max-min ordered attribute field?Is it possible to sort the features by an attribute programmatically?Populate empty attribute table from constantly growing CSV in QGISGrouping by attribute sum in QGIS?Getting number of objects in attribute table using PyQGIS?Calculating sum of parts of column based on another column using QGIS Field Calculator?Changing Number values to specific text in Attribute table (QGIS)Restoring attribute table order to original in QGIS?Creating column in attribute table from summarised fields using QGIS?Sum fields in ArcGIS
I have an attribute table in QGIS in which I would like to calculate the cumulative sum. The table is sorted by N (number of fatalities) and I would like to calculate the cumulative sum on F (frequency of accident), i.e. F_cumulative should be a sum of the current row and the rows above. How should I do this? Can I use a formula in the field calculator?
qgis table sum
New contributor
add a comment |
I have an attribute table in QGIS in which I would like to calculate the cumulative sum. The table is sorted by N (number of fatalities) and I would like to calculate the cumulative sum on F (frequency of accident), i.e. F_cumulative should be a sum of the current row and the rows above. How should I do this? Can I use a formula in the field calculator?
qgis table sum
New contributor
Welcome to GIS SE. As a new user, please be sure to take the short tour to learn about this site's focused Q&A format.
– Andy
yesterday
add a comment |
I have an attribute table in QGIS in which I would like to calculate the cumulative sum. The table is sorted by N (number of fatalities) and I would like to calculate the cumulative sum on F (frequency of accident), i.e. F_cumulative should be a sum of the current row and the rows above. How should I do this? Can I use a formula in the field calculator?
qgis table sum
New contributor
I have an attribute table in QGIS in which I would like to calculate the cumulative sum. The table is sorted by N (number of fatalities) and I would like to calculate the cumulative sum on F (frequency of accident), i.e. F_cumulative should be a sum of the current row and the rows above. How should I do this? Can I use a formula in the field calculator?
qgis table sum
qgis table sum
New contributor
New contributor
edited 1 hour ago
underdark♦
68.3k13177342
68.3k13177342
New contributor
asked yesterday
Robert KRobert K
161
161
New contributor
New contributor
Welcome to GIS SE. As a new user, please be sure to take the short tour to learn about this site's focused Q&A format.
– Andy
yesterday
add a comment |
Welcome to GIS SE. As a new user, please be sure to take the short tour to learn about this site's focused Q&A format.
– Andy
yesterday
Welcome to GIS SE. As a new user, please be sure to take the short tour to learn about this site's focused Q&A format.
– Andy
yesterday
Welcome to GIS SE. As a new user, please be sure to take the short tour to learn about this site's focused Q&A format.
– Andy
yesterday
add a comment |
1 Answer
1
active
oldest
votes
It can be done with an expression. Bear in mind this only works if the original table is already ordered with N descending as feature IDs increase. To get past NULL
values ruining the calculation, first change the values in your cumulative field to 0
with the field calculator. Then, again in the field calculator, write this expression (modifying the relevant layer/field names):
attribute($currentfeature, 'your_frequency_field') + attribute(get_feature_by_id('your_layer', if($id = 1, $id, $id-1)), 'your_cumulative_field')
This will calculate a cumulative sum in order of feature IDs by fetching the frequency field attribute value of the currently evaluated feature and adding the cumulative frequency field attribute value of the previous feature (with the exception of feature ID = 1 which will fetch its own value: 0
).
With a quick mockup of your data, this was my result summing on F and F_cum:
Thanks, but I want to calculate the cumulative sum of the current row and ALL the rows above. In Excel I calculate it as a sum of F on the current row with F_cumulative on the row above. I tried to change your expression to do this in QGIS but all I get is NULL values. Any suggestions on how I can do this?
– Robert K
8 hours ago
@RobertK I modified the answer to address the issues.
– Gabriel C.
4 hours ago
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "79"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Robert K is a new contributor. Be nice, and check out our Code of Conduct.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312921%2fadd-cumulative-sum-column-to-attribute-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
It can be done with an expression. Bear in mind this only works if the original table is already ordered with N descending as feature IDs increase. To get past NULL
values ruining the calculation, first change the values in your cumulative field to 0
with the field calculator. Then, again in the field calculator, write this expression (modifying the relevant layer/field names):
attribute($currentfeature, 'your_frequency_field') + attribute(get_feature_by_id('your_layer', if($id = 1, $id, $id-1)), 'your_cumulative_field')
This will calculate a cumulative sum in order of feature IDs by fetching the frequency field attribute value of the currently evaluated feature and adding the cumulative frequency field attribute value of the previous feature (with the exception of feature ID = 1 which will fetch its own value: 0
).
With a quick mockup of your data, this was my result summing on F and F_cum:
Thanks, but I want to calculate the cumulative sum of the current row and ALL the rows above. In Excel I calculate it as a sum of F on the current row with F_cumulative on the row above. I tried to change your expression to do this in QGIS but all I get is NULL values. Any suggestions on how I can do this?
– Robert K
8 hours ago
@RobertK I modified the answer to address the issues.
– Gabriel C.
4 hours ago
add a comment |
It can be done with an expression. Bear in mind this only works if the original table is already ordered with N descending as feature IDs increase. To get past NULL
values ruining the calculation, first change the values in your cumulative field to 0
with the field calculator. Then, again in the field calculator, write this expression (modifying the relevant layer/field names):
attribute($currentfeature, 'your_frequency_field') + attribute(get_feature_by_id('your_layer', if($id = 1, $id, $id-1)), 'your_cumulative_field')
This will calculate a cumulative sum in order of feature IDs by fetching the frequency field attribute value of the currently evaluated feature and adding the cumulative frequency field attribute value of the previous feature (with the exception of feature ID = 1 which will fetch its own value: 0
).
With a quick mockup of your data, this was my result summing on F and F_cum:
Thanks, but I want to calculate the cumulative sum of the current row and ALL the rows above. In Excel I calculate it as a sum of F on the current row with F_cumulative on the row above. I tried to change your expression to do this in QGIS but all I get is NULL values. Any suggestions on how I can do this?
– Robert K
8 hours ago
@RobertK I modified the answer to address the issues.
– Gabriel C.
4 hours ago
add a comment |
It can be done with an expression. Bear in mind this only works if the original table is already ordered with N descending as feature IDs increase. To get past NULL
values ruining the calculation, first change the values in your cumulative field to 0
with the field calculator. Then, again in the field calculator, write this expression (modifying the relevant layer/field names):
attribute($currentfeature, 'your_frequency_field') + attribute(get_feature_by_id('your_layer', if($id = 1, $id, $id-1)), 'your_cumulative_field')
This will calculate a cumulative sum in order of feature IDs by fetching the frequency field attribute value of the currently evaluated feature and adding the cumulative frequency field attribute value of the previous feature (with the exception of feature ID = 1 which will fetch its own value: 0
).
With a quick mockup of your data, this was my result summing on F and F_cum:
It can be done with an expression. Bear in mind this only works if the original table is already ordered with N descending as feature IDs increase. To get past NULL
values ruining the calculation, first change the values in your cumulative field to 0
with the field calculator. Then, again in the field calculator, write this expression (modifying the relevant layer/field names):
attribute($currentfeature, 'your_frequency_field') + attribute(get_feature_by_id('your_layer', if($id = 1, $id, $id-1)), 'your_cumulative_field')
This will calculate a cumulative sum in order of feature IDs by fetching the frequency field attribute value of the currently evaluated feature and adding the cumulative frequency field attribute value of the previous feature (with the exception of feature ID = 1 which will fetch its own value: 0
).
With a quick mockup of your data, this was my result summing on F and F_cum:
edited 4 hours ago
answered yesterday
Gabriel C.Gabriel C.
1,287320
1,287320
Thanks, but I want to calculate the cumulative sum of the current row and ALL the rows above. In Excel I calculate it as a sum of F on the current row with F_cumulative on the row above. I tried to change your expression to do this in QGIS but all I get is NULL values. Any suggestions on how I can do this?
– Robert K
8 hours ago
@RobertK I modified the answer to address the issues.
– Gabriel C.
4 hours ago
add a comment |
Thanks, but I want to calculate the cumulative sum of the current row and ALL the rows above. In Excel I calculate it as a sum of F on the current row with F_cumulative on the row above. I tried to change your expression to do this in QGIS but all I get is NULL values. Any suggestions on how I can do this?
– Robert K
8 hours ago
@RobertK I modified the answer to address the issues.
– Gabriel C.
4 hours ago
Thanks, but I want to calculate the cumulative sum of the current row and ALL the rows above. In Excel I calculate it as a sum of F on the current row with F_cumulative on the row above. I tried to change your expression to do this in QGIS but all I get is NULL values. Any suggestions on how I can do this?
– Robert K
8 hours ago
Thanks, but I want to calculate the cumulative sum of the current row and ALL the rows above. In Excel I calculate it as a sum of F on the current row with F_cumulative on the row above. I tried to change your expression to do this in QGIS but all I get is NULL values. Any suggestions on how I can do this?
– Robert K
8 hours ago
@RobertK I modified the answer to address the issues.
– Gabriel C.
4 hours ago
@RobertK I modified the answer to address the issues.
– Gabriel C.
4 hours ago
add a comment |
Robert K is a new contributor. Be nice, and check out our Code of Conduct.
Robert K is a new contributor. Be nice, and check out our Code of Conduct.
Robert K is a new contributor. Be nice, and check out our Code of Conduct.
Robert K is a new contributor. Be nice, and check out our Code of Conduct.
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f312921%2fadd-cumulative-sum-column-to-attribute-table%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Welcome to GIS SE. As a new user, please be sure to take the short tour to learn about this site's focused Q&A format.
– Andy
yesterday