I want to add columns in a shapefile to make calculations on it, those calculations are supposed to measure the size per land cover type and therefore I need that my calculation adapts to my filters.

I do my filters in the query builder because it does not work from the attribute table.

When I filter my layers the results of my calculation don't change. I don't understand why and I don't know how to solve this issue.

1 Answer 1


Using a regular field calculation, the result is static and would need to be re-calculated each time a change is made. To make the output dynamic, you can create a virtual field that will adapt to a filter.

Here I make a field called adaptive that is the sum of another field length

enter image description here

With no filter applied on the layer:

enter image description here

With the filter fid > 1:

enter image description here

The virtual field persists when you save, close, and re-open your project. However, it does not exist in the actual shapefile, so you would need to export the layer as a new shapefile if you want to keep a static version of your result (to hand to someone else, for example).

  • 1
    Thank you, I didn't know about these, or that there was a Field Calculator button in the Attribute Table that works slightly differently from the one in the Toolbox, like offering the Create Virtual Field option. This shouldn't have surprised me, since I came to QGIS from ArcMap, which does the same thing.
    – Cowirrie
    Commented Feb 12, 2022 at 10:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.