0

In QGIS 3.22.14, I'd like to present in the print composer a sub- and total sum in one table. The values in the attribute table can be anything (area, count, etc.), the key is to present them in one table.

The table in the example below shows the sub-total surface area, grouped according to the shape of the objects. I would like to add another row with the total area of all objects.

enter image description here

So far I have created an empty field in the attribute table and then used CASE query, another solution is to use a virtual layer. But I'm looking for a more elegant solution that doesn't require i.e the attribute table editing. Is there any?

1
  • Can you provide sample data/screenshots? And clarify the requirements: automatically compute values from fields based on expressions: what are they? Have them available as a table, have that table displayed in the Layouts for print, with total & sub totals
    – Kasper
    Commented Feb 6, 2023 at 12:10

1 Answer 1

1

You can use a Fixed table to do that, instead of an Attribute table.

Add lines/columns according to your needs, and in the surface expression, use the relevant formulas for 'circles', 'squares' and assumming that the layer is named 'shapes':

For Circles: aggregate('shapes','sum',$area,filter:="desc"='circle')

For Squares: aggregate('shapes','sum',$area,filter:="desc"='square')

For the Total: aggregate('shapes','sum',$area)

As this Table is not tied to a particular layer, the aggregate function does the job to :

  • select the appropriate layer,
  • do the math: function/expression (sum the $area),
  • and filter on "desc" properties to get the desired subset/total

enter image description here

enter image description here

2
  • Thanks for the answer, but it looks more time-consuming, especially when more attributes need to be presented and their number may change as the project develops.
    – flisior
    Commented Feb 13, 2023 at 10:15
  • You can maybe stack two tables, one for the total, the other one dynamic per attribute value
    – Kasper
    Commented Feb 13, 2023 at 12:19

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.