2

I have a survey form and some features (trees) will be grouped using the same "TreeNumber".

Hopefully, I can write an expression that means users only have to fill in most of the data for one feature, and the expression with fill in the gaps in another set of virtual fields for the other features.

So far I have tried the expression below which I hoped would return the maximum value from all the features filtered to match the current feature "TreeNumber" but it just crashes QGIS.

maximum("Species", "TreeNumber" = attribute($currentfeature, "TreeNumber"))

1 Answer 1

2

Try this expression:

with_variable(
    name:='currentTreeNumber',
    value:="TreeNumber",
    expression:=maximum(
        expression:="Species",
        filter:="TreeNumber"=@currentTreeNumber
        )
    )

$currentfeature inside an aggregate returns features of the aggregation, you can store the value of the field of interest of the current feature in a variable with the with_variable() function and then compare it with the value inside the aggregate.

1
  • Many thanks! I have to look at the help file for with_variable
    – Sethinacan
    Nov 2, 2022 at 20:27

Your Answer

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

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