qgis – Setting Value Relation Relative to Other Field in QGIS 3

qgisqgis-3valuerelation

I've been trying to search for a solution for this to no avail.

I have a value relation set up and want another field connected and relative to this.

Example:
Field 1 (Value 1)
Field 2 (Value 2)

Value 1.1 = Value 2.1
Value 1.2 = Value 2.2
And so on.

So if i add Value 1.1 to field 1 i want it to automatically add Value 2.1 to field 2.

Field 2 does not need to be editable so it only needs to go one way so to speak.

Is there a solution for this?

EDIT:
Clarification what i want to do.
The actual values i want to use are tree species names.
If "Acer platanoides" is added to field 1 i want "Maple" in field 2.
I have a value relation set up with the species name but want the common name to be added automatically as well. Preferably in a separate field.

Best Answer

We can use a Virtual Field to do this. Create Field 2 as a virtual field and with an expression.
In the 'Maple' example above we want to turn a string into another based on the Field1 value. For this we can use a CASE Expression such as:

CASE 
WHEN "FIELD1" = 'Acer platanoides' THEN 'Maple'
WHEN "FIELD1" = 'Quercus alba' THEN 'White Oak'
END

As values are added or edited to Field1 Field2 will update once a save is made. We can add as many WHEN checks to the CASE as we need.

In my example below Field1 has the name 'HubDist' & we are dealing with numbers not strings

example image

Related Question