In QGIS, I'm working with two layers that are related to each other through the value-relation widget.
Layer 1: TEST
- fields:
"id"
;"LIB"
;"odc_ID"
;"Code"
Layer 2: ASSO_TEST
- fields:
"id"
;"LIB"
;"CORRESP"
The value relation widget is on ASSO_TEST, field LIB
I'm attempting to generate a list containing one occurrence of each unique value in the LIB
field, based on the corresponding values in the Code
field within the ASSO_TEST layer.
I encounter an issue when there are multiple features with identical labels, leading to duplicate entries in the value-relation list.
In a previous project, I was able to filter this list using the following expression:
id = array_first(array_agg("id", group_by:= "Label"))
However, in this current project, I'm encountering difficulties and I'm unsure of what I might be doing wrong.
I have tried several approaches, like :
"Lib" = (array_distinct(array_agg("Lib", group_by:='odc_ID')))
"Lib" IN (array_agg("Lib", group_by:= 'odc_ID'))
"odc_ID" IN (array_distinct(array_agg("odc_ID", group_by:= "code")))
array_find("odc_ID",array_distinct(array_agg("odc_ID", group_by:= "code")))
"Lib" IN (array_to_string(array_distinct(array_agg("Lib", group_by:= "code")), ', '))
array_contains(array_distinct(array_agg("odc_ID", group_by:= "code")),"odc_ID")
I wouldn't have tried out so many variations of the code if I properly understood what I'm doing. But for my previous projects, I didn't have issues.
Here is a link to download a test project.
LIB
then the expression is"id" = array_first(array_agg("id",group_by:="LIB"))
- just change the group_by parameter. It's already answered here gis.stackexchange.com/a/431609/98784 and in other places. The filter can be very slow on large datasets. Also, not sure what you meant by filteringLIB
based onCode
field in ASSO_TEST?... there is noCode
field in ASSO_TEST.