I found this question when looking for my answer Referring to the parent layer with aggregate functions in QGIS
I need to do something similar. In another words I need to join attributes by field value using the expressions in Field Calculator. I want values of a given layer to sum up based on the value of an attribute in an atlas. Here is my code:
aggregate( layer:=*child layer*, aggregate:='sum', expression:=*child layer attribute to be summed*, filter:=*Child layer attribute to check*=attribute(@parent,*parent attribute to check*) )
I am using the expression
attribute(), but I don't know if this exists, it's just something I have seen in the linked topic, but it doesn't work.
There is probably a work-around using an aggregate within aggregate, but this seems too complicated.
To explain a little more. I have polygons (child layer) with values inside several areas (parent layer, also polygons). Previously I added the parent area codes to the child polygons polygons in the past based on location. Now I am getting incorrect sums based on aggregate filtered by location, I need to validate the calculations and I cannot figure out another way to check, so I need to sum it up by filed values (the ones I added also based on location). I probably should be looking on different ways to check my calculations, but this is the step I am at and need help.