1

I create new field based on other fields. For example; if "Field_A" is smaller than "Field_B", value of new field is 'A', otherwise it is 'B'. So I want to create new variable for this case within Expression area.

It's possible in QGIS 3 by means of with_variable function. But QGIS 2 don'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?

  • 2
    The 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 May 15 '18 at 18:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.