I have a simple attribute table structured in this way:
Features | Attribute1 | Attribute2 | Attribute3 | Attribute4 | Count |
---|---|---|---|---|---|
F1 | 5 | 0 | 1 | 3 | 3 |
F2 | 0 | 0 | 0 | 4 | 1 |
F3 | 1 | 2 | 0 | 0 | 2 |
F4 | 12 | 4 | 6 | 9 | 4 |
And I need to populate the 'Count' field depending on how many attributes have a value different from 0. In Excel I would use a simple Countif
function such as Countif(Attribute1:Attribute4; "<>0")
. In QGIS I tried to use this:
COUNT(CASE WHEN Attribute1 <> 0 THEN 1 END) +
COUNT(CASE WHEN Attribute2 <> 0 THEN 1 END) +
COUNT(CASE WHEN Attribute3 <> 0 THEN 1 END) +
COUNT(CASE WHEN Attribute4 <> 0 THEN 1 END) +
but I don't get the right result.