I create new field based on other fields. For example; if "Field_A"
is smaller than "Field_B"
, the value of the new field is 'A'
, otherwise it is 'B'
. So I want to create a new variable for this case within Expression area.
It's possible in QGIS 3 by means of with_variable
function. But QGIS 2 doesn't have that function.
In QGIS 3:
# mn -> new variable
with_variable( 'mn', min( "Field_A", "Field_B" ),
if( @mn = "Field_A", 'A', 'B' ) )
or
with_variable( 'mn', min( "Field_A", "Field_B" ),
case when @mn = "Field_A" then 'A' else 'B' end )
In QGIS 2, I want to write something like that:
mn = min("Field_A", "Field_B")
CASE
WHEN mn = "Field_A" THEN 'A'
WHEN mn = "Field_B" THEN 'B'
END
I don't mean global or project variable, I'm asking to create a new variable to be used in Expression area scope.
How can I do that within Expression area in QGIS 2?
-
9The with_variable() function is a new feature in QGIS 3. As far as I can tell there's no equivalent function in QGIS 2.csk– csk2018年05月15日 18:15:14 +00:00Commented May 15, 2018 at 18:15
1 Answer 1
The with_variable() function is a new feature in QGIS 3 (see changelog). There's no equivalent function in QGIS 2.
with_variable(name, value, node): This function sets a variable for any expression code that will be provided as 3rd argument. This is only useful for complicated expressions, where the same calculated value needs to be used in different places.
-
This
community wiki
answer is given in order for this question to be marked as "answered".Comrade Che– Comrade Che2025年01月15日 12:40:33 +00:00Commented Jan 15 at 12:40