I am attempting to use aggregate() or relation_aggregate() in order to populate a label on an atlas powered print composer using QGIS 3.8, but am having issues with both.

My goal is to show the number of children that satisfy a certain query on the an atlas that is powered by the parent.

I first created a relation in the project properties, saved, closed, and reopened project.

I added a label to my print composer, and have tried the following syntax:

Using aggregate

[%aggregate('child_layer', 'count', "child_layer_field" is 'OUI', attribute($currentfeature, 'foreign_key') = attribute(@parent, 'primary_key'))%]

Using relation_aggregate:

[% relation_aggregate('relation_key', 'count', "child_layer_field" is 'OUI')%]

In both cases, the label displays a number, but it is simply the total number of children related to the parent (not taking into consideration the expression "child_layer_field" is 'OUI').

Am I misunderstanding how this works or am I doing something wrong? Should this work with 2.18 as well?

1 Answer 1


You need to put any filter conditions together in the one parameter (so attribute($currentfeature... ) AND "child_layer_field" = 'OUI')

And the expression to aggregate - the third parameter, after the type of aggregate - should be a field or a simple modification thereof (e.g. title("child_layer_field") or "child_layer_field" * 10) not a logical condition.

  • Is this a modification of aggregate or relation_aggregate?
    – user25976
    Sep 13, 2019 at 19:05
  • aggregate() - I think you can modify appropriately for relation_aggregate(), in field calc look at the description of the function on the right hand side to work out which parameters to change. Remember to put the filter conditions together in either case.
    – she_weeds
    Sep 14, 2019 at 0: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.