2

I cant find a solution to use the value of the current atlas entity in the aggregate function in the filter expression part.

Example:

aggregate('layer_to_aggregate','count',"field_form_layer_to_aggregate_to_aggregate","field_from_layer_to_aggregate_to_filter"="field_from_atlas_layer")
2
  • I'm not sure you can aggregate by atlas layer but, have you tried to set the filter as filter:= "field_from_atlas_layer"?
    – Albert
    Commented Oct 25, 2018 at 16:09
  • In my case the layer from which I want the aggregate has to be filtered and the entities that have to be filtered are those which match the value of the atlas current atlas entity: "field_from_layer_to_aggregate_to_filter"="field_from_atlas_layer". The problem is the aggregate function don't understand "field_from_atlas_layer"` to be the atlas layer and I think inside the aggregate function every fields are supposed to be from the 'layer_to_aggregate'.
    – Charles
    Commented Oct 26, 2018 at 8:34

2 Answers 2

1

Once you're in the aggregate() command it only focuses on the layer you're aggregating, so you can't reference the atlas layer field normally with just double quotes (it thinks that's on the aggregated layer).

To tell it you are talking about a field in the atlas layer (coverage layer), try referring to the atlas layer specifically using @atlas_feature and attribute(). Note that the field is referred to with single quotes and is case-sensitive

aggregate('layer_to_aggregate','count',"field_from_layer_to_aggregate_to_aggregate",
          "field_from_layer_to_aggregate_to_filter"=
          attribute(@atlas_feature,'field_from_atlas_layer'))
1
  • Thank you! Another similar solution is to use with_variable(): with_variable( 'field_from_atlas_layer',"field_from_atlas_layer", aggregate('layer_to_aggregate','count',"field_from_layer_to_aggregate_to_aggregate", "field_from_layer_to_aggregate_to_filter"=@field_from_atlas_layer') )
    – Charles
    Commented Mar 13 at 13:46
0

I found that I needed to use the relation function of the QGIS project and use the relation_aggregate function like that: relation_aggregate( relation:='relation_name',aggregate:='sum',"child_field_to_aggregate")

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.