I have two layers, a "foo" points layer, and a "bar" polygon layer, each has a "foobar_n" column and a datetime column.

These are survey layers for use in QField, and the end result required is for the column "foobar_n" to be sequential based on when the point/polygon object was taken.

Currently I retroactively apply these numbers using a python script using the datetime column from each layer.

However is it possible to apply a CASE WHEN argument to the "foobar_n" columns in each layer so that I sequentially number as I survey?

The option to do this manually during survey is not practical.

1 Answer 1


Yes, you can. In your default value for foobar_n, use the following expression

Max(aggregate('foo','max', "foobar_n"), aggregate('bar','max', "foobar_n"),0)+1

aggregate() returns an aggregate value (e.g. max, count, sum etc) from features on the another layer. The expression contains an aggregate() for each layer and the value zero, inside a Max() function. The 0 value is to accommodate the case where there are no features with values in foobar_n. I then add 1 to the result to get the next in sequence.

Hope that helps.

  • Aggregate! I will try this later today. Looks like the required solution, and update.
    – Stew
    Feb 7, 2022 at 7:06
  • this was solution. Answer accepted.
    – Stew
    Feb 7, 2022 at 17:36

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.