Inside a GeoPackage, I have a table without geometry that stores information about trees inventory. I also have a point layer representing trees. A single record in the inventory table can be related to one or more trees - this relationship is defined in the project.
The inventory table has fields that summarize data from the tree layer. I want these fields to be updated automatically based on the values in the tree layer. Specifically, I want to count the number of trees and list unique species by tree status.
For example, I have an inventory case with three trees: two to be cut down and one to be replanted. I want to display these counts separately and also show species names as a summary.
However, I cannot get the expression to evaluate correctly when applying a condition based on the "status" field. Instead, the total count is always 3, rather than being split into 2 and 1 depending on the tree status. Similarly, all species are listed together, whereas it should show "Pine" for trees to be cut down and "Spruce" for the tree to be replanted.
I am using the following expressions, but the filtering condition doesn't seem to work, and I can't figure out the correct syntax.
Expression for counting trees:
relation_aggregate(
'inventory - trees',
'count',
$id,
"status = 'cut down'"
)
Expression for displaying unique trees species:
array_to_string(
array_sort(
array_distinct(
relation_aggregate(
'inventory - trees',
'array_agg',
"species",
"status = 'cut down'"
)
)
),
', '
)

