1

I have an attribute table containing information about area, region, and samples. The table structure resembles the example shown below:

enter image description here

My goal is to automate the generation of IDs when adding new point features to my layer (similar to this). I plan to achieve this using the 'Default value' feature in the attributes form of the layer properties.

The desired pattern for generating IDs is as follows:

  • Group the data by the columns 'area', 'region', and 'sample'.
  • Identify the maximum number of items within each group and increment this number by 1.
  • Pad the resulting number to four positions with leading zeroes.

1 Answer 1

3

You can try the following expression for the default value in the form:

"area" || '-' ||  "region" ||'-' ||  "sample" || '-'  || 
     lpad(array_length( 
     array_agg(expression:="area" || "region" || "sample",
     group_by:= ("area" || "region" || "sample"))) + 1, 4 ,0)
1
  • Nice! I had the different chunks setup individually, but did not know how to combine them. Works perfectly, thanks!
    – Fjedsen
    Commented Feb 14 at 7:43

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.