When i try to get an automatic fieldname with the following expression: coalesce("Borserie",NULL,'Skriv inn ledig nummerserie') it doesn't get the value/string from the table? The weird thing is that it does look right in the preview? Expression

The table looks like this: enter image description here

And the result looks like this: enter image description here

Tried and tried for a couple of days but nothing seems to work out. Anyone with some good hints or a solution?

  • 4
    can you add some more about what you are trying to achieve? I'm fairly sure the NULL inside a coalesce statement is redundant
    – Ian Turton
    Dec 4, 2019 at 17:21
  • Sure. :) I'm trying to retrieve the value, in this case 'GAL' from the "Borserie" field, when adding new points (BorID). I also tried this one: CASE WHEN "Borserie" IS NULL THEN 'Skriv inn ledig nummerserie' ELSE "Borserie" END Dec 4, 2019 at 17:28
  • When you add a new feature, it is expected that the fields are either Null or using their default expression, so the entire coalesce can be skipped and replaced by the default value / your text. See this post
    – JGH
    Dec 4, 2019 at 17:59
  • Apparently I already wrote the same answer to different question. Oops.
    – csk
    Dec 4, 2019 at 18:10

1 Answer 1


It seems a default field value cannot take values from other fields during new feature creation. I believe this is because the default value is applied as soon as you right-click to finish digitizing, at which point the other fields don't have any values. But by that logic one would expect "BorID" to always be 'Skriv inn ledig nummerserie', and instead it's NULL. So that issue is not fully explained. Regardless, the workarounds below should help.

Workaround One: Check the option to "Apply default value on update." After creating a new feature, the field with the default value will be blank. Then edit the feature slightly (eg, move a vertex, or move the feature a very small distance, etc). Now the default value should be auto-filled.

Downsides of this method:

  • This is not a good workaround if you need to occasionally edit the default value. Your edits to that value will be erased any time the feature is updated.
  • It takes an extra step. If you're digitizing a lot of features, those extra steps will add up. In that case, you can create all the new features first, then select and slightly move all of them at once.

Workaround Two: Use a virtual field instead of a field with a default value. Use the Field Calculator to add a new field, and check the option to make it a virtual field. Use the same expression you would have used in the default field value.

Downsides of this method:

  • Virtual fields are saved in the project, not the source data. If you need this field in the source data, you'll need to remember to use the Field Calculator to copy the virtual field into a regular field.
  • You can't edit a virtual field. So if you want to change the calculated value, you'll need to store that new value in a separate, non-virtual field. Then anytime you try to use the value, you'll need a conditional statement that chooses the non-virtual field value unless its null, and chooses the virtual field if the non-virtual field is null. Like this:
    • if("regular_field" is null, "virtual_field", "nonvirtual_field") or
    • case when "nonvirtual_field" is null then "virtual_field" else "nonvirtual_field"

Additional notes: All of your expressions seem fine, although as Ian Turton pointed out the NULL inside of coalesce is redundant. So use any of these expressions in either of the two workarounds above.

  • coalesce("Borserie",'Skriv inn ledig nummerserie')
  • CASE WHEN "Borserie" IS NULL THEN 'Skriv inn ledig nummerserie' ELSE "Borserie" END
  • if("Borserie" IS NULL,'Skriv inn ledig nummerserie',"Borserie")
  • Thanks a lot for your answer. Tried workaround one but that doesen't seem to help. It then keeps filling out 'Skriv inn ledig nummerserie' and not the value allready in the field. Even though the preview shows it correct? Workaround two doesn't seems like it suits our workflow. Guess the last option are to just use the modify all attributes of the selected features, when you're done adding all the points. It's rather strange though since I'm using this expression: maximum("BorID")+1 in the same input scheme. Should work the same way I guess. Dec 4, 2019 at 19:42
  • Did you try it with all three expressions I suggested? They all do the same thing, but trying it with multiple versions might fix the issue without really knowing what was wrong.
    – csk
    Dec 5, 2019 at 16:45

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.