Instead of repeating four times the Select by attribute
and then Extract selected features
, you can use a much simplified version with just one algorithm Extract by expression
. Create an expression that fulfills the conditions for all four variables at once.
Like "value" in (1,2,3,4)
selects all those features where field value
is 1, 2, 3 or 4. You can replace the numbers by the variables and have to enclose the expression as a string in an eval()
function:
eval ('value in ( @variable1 , @variable2 , @variable ,@variable4 )')
This works even if one ore more of the variables are NULL
.

Input = red points: running the model with two variables empty extracts all the features where value
corresponds to one of the variables not NULL
(here: 2
or 3
). Output: blue points

Edit
As you stated in your comment, you want to extract only exact matches. In this case, the solution above works as well, however you must adapt the expression - the rest remains the same.
Use this expression:
eval (
'array_sum (
with_variable (
''array1'',
array_foreach (array (@v1,@v2,@v3,@v4), if (@element>0, @element,''null'')),
with_variable (
''array2'',
array_foreach (array (value1,value2,value3,value4), if (@element>0, @element,''null'')),
array_foreach (
generate_series (0,3),
@array1 [@element] = @array2 [@element]
)
)
)
)=4'
)
You might have to adapt:
- Line 5: name of the variables (here:
v1
, v2
etc.)
- Line 8: name of attribute fields (here:
value1
, value2
etc.)
Red points, labeled with value1
to value4
(what in the label appears as 0 in fact is NULL
); yellow circle is the output-point of the model: only exact matches in the same order (1,3,5,0
) are extracted; values 1,3,0,0
and or 1,5,3,0
(red circle) are ignored:

I also add a generic solution if you do not have exactly four elements to compare, but a flexible number. Just make sure both number of variables and of fields (lines 4 and 7) are the same length (like: array (@v1,@v2)
and array (value1,value2)
for two elements):
eval (
'with_variable (
''array1'',
array_foreach (array (@v1,@v2,@v3,@v4), if (@element>0, @element,''null'')),
with_variable (
''array2'',
array_foreach (array (value1,value2,value3,value4), if (@element>0, @element,''null'')),
array_sum (
array_foreach (
generate_series (0,array_length(@array1)),
@array1 [@element] = @array2 [@element]
)
)= array_length(@array1)
)
)'
)