I´m working with two layers in QGIS:

  1. First one with point geometries representing water quality sampling places (LAYER A).

  2. The second is a spreadsheet (no geometries) that contains pollution values at different times (LAYER B).

Both layers linked with a relate (one to many) based on the station ID. Relate works as the LAYER B data are preented in the info form when clicking LAYER A features.

The aim is to get time series graphs using Data Plotly plugin, but apparently it is not designed to work with relates.

I´ve come to the conclussion that the only way to get the plots is to set LAYER B in the plugin and then limit the feature subset to the records that match the STATION_ID of the selected feature in LAYER A. I´ve tried this with an expression of the sort


where layer is LAYER A, aggregate is 'concatenate', and expression would be the field contaning the STATION_ID

but cannot guess what the expression of the filter should be so that only the data of the selected feature is presented in the plot. Also i´m aware that in case that more than one features are selected, the concatenate wouldn`t work.

Any idea how to solve this? Another way to get the selected STATION_ID from LAYER A?

1 Answer 1


Not sure if I understand your question correctly, but here is how you can get selected features of another layer using aggregate() expression as asked in your question's title:


Of course you can also use other stuff than 'array_agg' and other fields/features/geometries than "id". Also you could get the not selected features, by simply using not in front of is_selected():

aggregate('LayerB','array_agg',"id",not is_selected('LayerB',$currentfeature))

The trick is to pass two arguments to the is_selected() function in the filter argument of aggregate(): the layername and the feature.

If the function is called with both a layer and a feature, it will return true if the specified feature from the specified layer is selected.

  • Yesss! Thank you MrXquared, that worked. Although I had problems with array_agg and change to concatenate instead. I suppose because STATION_ID contains only one value, and dont´t match an array type. But I have to try again and see.
    – janavaarro
    Commented Jul 14, 2022 at 21:14

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.