Summarizing fields with same ID in QGIS Field Calculator

field-calculatorfields-attributesgroupingqgissummarizing

I am looking for a command, that sums the value of the field "Baulast" if they have the same "ogc_fid" and if there is a Number in the field "WEA". If there is no number in the field "WEA" -> 'keine Baulast'.
Maybe something like

if("WEA">NULL, sum("Baulast","ogc_fid"), 'keine Baulast')

So as seen on the Picture, I want to sum the fields that have same ogc_fid and have a number in "WEA".

enter image description here

Best Answer

As an alternative you may try this expression:

if("WEA" IS NOT NULL,
    array_sum(
        array_agg(
            "Baulast",
            group_by:="ogc_fid",
            filter:="WEA" IS NOT NULL
            )
        ),
    'keine Baulast'
    )