I need to create an attribute with cumulative sum of another attribute. The values are sorted by a string attribute. I just found posts that involved the numerical id of the features.
I've tried to make a expression with the previous feature name but it only works for the first three features in the table, all after that remain NULL.
That's the expression:
if (name = 'P00-P01', attribute('dist'), attribute('dist') + attribute(get_feature('route', 'name', if (to_int(substr(name, 2,2))-1<10, concat( 'P0', to_string(to_int(substr(name, 2,2))-1),'-',substr(name ,0,3 )), concat( 'P', to_string(to_int(substr(name, 2,2))-1),'-',substr(name ,0,3 )))),'cum_dist'))
Using the index in the expression the result remains the same.
if (name = 'P00-P01', attribute($currentfeature, 'dist'), attribute($currentfeature, 'dist') + attribute(get_feature_by_id('route', $id-1), 'cum_dist'))
I've tried also the aggregated()
function but every time the QGIS crashes.
Someone have a guess about this bug?
dist
have an expression$lenght
of sequential lines to provide these values. I've tried to create another virtual field with the sum of other attribute, also virtual and integer. The result was the same bug, only the three next features were updated.