I have GeoPackage file with parcels (polygons) and an Excel table with parcel owners. As one parcel can have multiple parcel owners I established a one to many relationship. Now I wish to label the parcels with one or more owners (as many as the parcel has).

The parcel layer and Excel table have mutual Parcel IDs.

How could I do this in QGIS?

1 Answer 1


You can use a custom function in the label expression editor

  • Assuming your parcels attribute table is structured like this:

enter image description here

from qgis.core import *
from qgis.gui import *

@qgsfunction(args='auto', group='Custom', referenced_columns=[])
def concat_field_values(feature, parent, context):
    ## get field names of layer using 'context' argument
    fields = context.fields().names()
    ## get fields with 'name' in the field name
    fields = [x for x in fields if 'name' in x.lower()]
    ## loop through fields and get list of values, excluding null values
    owners = [str(feature.attribute(x)) for x in fields if str(feature.attribute(x)) != "NULL"]
    ## join list into string, using the new line escape character
    label_string = '\n'.join(owners)
    return label_string

If you are unsure how to make a custom function

  • Click the expression editor button

enter image description here

  • Select the Function Editor tab
  • Make a new function and paste the code
  • Click Save and Load Functions

enter image description here

  • Back in the Expression tab, enter the function name, followed by parentheses

enter image description here

enter image description here

  • Hi Mat. this was helpfull definetly but I have bit different table for example I have for one geometry following entries: id,parcelNumber,parcelOwner and in next line for same parcel i have different owner so based on number of identical parcel numbers I need to concatenate (join) parcel owners Commented Jun 18, 2022 at 18:07

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.