2

I am trying to get the Field Calculator on QGIS to create an autoID and I am using this expression

'5EL_' ||@row_number

It works in the preview, but when executed the field is blank.

How do I fix this?

I have also tried

'5EL_' ||$id

but for some reason I am getting -x for the id part e.g. 5EL_-32 with the next feature drawn being 5EL_-33.

7
  • Please remember to always add the exact software in use in each Question.
    – Vince
    Aug 18, 2022 at 11:47
  • Have you explored $rownum?
    – PKG
    Aug 18, 2022 at 12:27
  • if its working in preview but not executed, then most probably the reason is a different data field type. try again '5EL_' ||@row_number on a text field. Aug 18, 2022 at 12:34
  • What file format is it? Is that virtual layer? Aug 18, 2022 at 12:35
  • I have tried $rownum and there is no such thing (red squiggly underlined). It is a virtual field and I do have it on text - I have tried several different types and still not working Aug 18, 2022 at 12:41

1 Answer 1

4

You are on the right track. Use '5EL_' ||$id. This expression produces a string. Therefore, the field you create have to be Text, otherwise, you get NULL.

enter image description here

In edit mode, QGIS uses negative id numbers. After saving, they are converted to suitable sequential positive numbers.

enter image description here

2
  • I have tried making new features and saving and this is not the case unfortunately Aug 18, 2022 at 13:22
  • For some reason it is now working 9not sure why wasn't before) - thank you Aug 18, 2022 at 13:37

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.