You can use a custom function in the label expression editor
- Assuming your parcels attribute table is structured like this:
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
- Select the Function Editor tab
- Make a new function and paste the code
- Click Save and Load Functions
- Back in the Expression tab, enter the function name, followed by parentheses