I have two layers imported to QGIS 3.28.1 Firenze; 1* points and 1* polyline.

In Model Builder I have run an algorithm on the polyline which outputs points with an attribute named "KP"

Using the syntax

"KP" in (1,2,3,4)

I can select points from this layer where "KP" appears in a manually entered list. I am trying to select points from this layer where "KP" appears in the input points layer, attribute name "KPto".

I try

"KP" in (@KPzones_xyz, "KPto")

The script executes without error however nothing is returned. What should the correct syntax be?

QGIS Model Builder expression

enter image description here

  • My magic 8-ball says you need to provide more details on your data, especially field names, contents and common keys.
    – Erik
    Jan 10, 2023 at 15:37
  • Thanks. Field names of interest are "KPto" on layer KPZones_xyz and "KP" on layer "Field_calculator_OUTPUT". Both of which are type double. I don't understand the reference to magic 8-ball. I haven't come across this in QGIS before, is it a debugging tool?
    – CJA888
    Jan 10, 2023 at 15:54
  • en.wikipedia.org/wiki/Magic_8_Ball - and I still have no idea, how your fields should interact. Is there a common key/ID? What exactly are you trying to achieve?
    – Erik
    Jan 10, 2023 at 15:58
  • I see, thanks for the clarification on magic 8 ball, I have heard of it but didn't know what it does. I also have no idea how my fields should interact. No there is no common key. That is the problem, I am trying to select fields "KP" from my points layer where "KP" matches "KPto" from a different layer. You can think of "KPto" being a representation of (1,2,3,4) which was the manual text entry which works to select the required field.
    – CJA888
    Jan 10, 2023 at 16:12

1 Answer 1


If you run the select by expression on one layer to select the attributes pointid to be within all id fields from another layer layer1, one expression that will work is:

     aggregate(layer:='layer1', aggregate:='array_agg', expression:="id"),

The aggregate() creates an array with all existing value of the layer1 attribute

array_contains() checks if the current layer attribute is part of the list

Applied to layer2, where attributes pointid are in the id of layer1:

enter image description here

If I get your attribute names well, it should read like this in your case:

     aggregate(layer:='KPzones_xyz', aggregate:='array_agg', expression:="KPto"),
  • 1
    Accepted as solution thank you- I removed explicit naming so code is as below for ease of reading, and kept the explicit case in comments array_contains( aggregate('KP_xyz', 'array_agg', "KPto"), "KP")
    – CJA888
    Jan 11, 2023 at 8:28

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.