I have given my objects multiple value that represent a "need for action". I want to sum up those individual numbers to an overall "pressure for action".
I have multiple objects with values in ~10 fields.
Sometimes, fields do not have a value (NULL). Sometimes I have a 99 as an error value.
If I just sum up my fields by "field1" + "field2" + "field3" + ..., I end up with NULL as result, if there was a NULL in any value. So I need to exclude NULL values from my expression. Also, I want to exclude my 99 values.
Sample data:
| id | field1 | field2 | field3 | field4 | expected result |
|---|---|---|---|---|---|
| 1 | 5 | NULL | 2 | 17 | 24 |
| 2 | 2 | 1 | 1 | 9 | 13 |
| 3 | 0 | 2 | 99 | 12 | 14 |
| 4 | NULL | 1 | 99 | 19 | 20 |
I am looking for either an expression I can use or if only possible with Python, a code that I can just copy/paste and edit my column names (I do not know Python, so I would need a proper explanation of the code).
I imagine a code that first checks the value of a field. If the value is NULL or 99, it skips to the next field. All other values get added up.
I found this question : Calculating field in which null values may be present?, which describes a somewhat same problem, but is focused on ArcGIS. I also have no clue what the given code there says and how to adapt it to my problem.
I can not change the numbers in my value fields as they are important on their own.
I am using QGIS 3.24 on Windows 10.
sumexpression works with a filter? – Erik Mar 04 '22 at 08:25