Using QGIS 3.6.1 I have a layer with areas and a table with entries related to the areas:
A relation is defined like this:
What I would like to achieve is to label the areas with the number of related table entries using relation_aggregate
function as shown here:
relation_aggregate ('my_relation', 'count', 'text') || ' Table entries'
As can be seen in the screenshot (Output preview), the label expression delivers a valid result as expected (e.g. "4 Table Entries"), but labels are not shown in the map:
Another thing I tried using the aggregate
function is the following:
with_variable('my_id', "id", aggregate('table', 'count', 'id', "flaeche_id" = @my_id)) || ' Table Entries'
Which gives a totally weird result depending on which area is shown in the current map extent, i.e.
1) Both areas labelled with "4 Table entries", but the lower has only one related table entry (see table above):
2) If the map extents only to the southernmost area, the label shows correctly "1 Table entries":
So all in all with my first approach I have no labels and with the second approach I have wrong labels.
I think I'm little stuck with the aggregate...
functions in QGIS 3, am I using them the wrong way or are there any other approaches to the labeling I want to achieve?