4

I have one table containing many columns. Using the Field Calculator, I want to create a new column containing (for each line) the sum of all columns values.

I cannot find the correct expression to do this sum.

1

1 Answer 1

7

Using the Field calculator to:

  • sum up columns without NULL values:

    "column1" + "column2" + "column3"
    
  • sum up columns with NULL values:

    "column1" +  (CASE WHEN  "column2" IS NOT NULL THEN "column2" ELSE 0 END) + "column3"
    

Make sure the columns are integer or float values.

11
  • Thanks, that's what I've been trying but it doesn't work. I was wondering if it was me or some other sort of problem. Glad to know it's not me !
    – Legzav
    Commented Oct 8, 2013 at 6:35
  • Can you please specify what do you mean by it doesn't work at all or it gives you incorrect results? Commented Oct 8, 2013 at 6:46
  • It doesn't work at all. I get only NULL values. It also desn't show any preview result in the field calculator.
    – Legzav
    Commented Oct 8, 2013 at 6:54
  • @Legzav: Can you confirm that all the columns (input and output) are of Numeric Data type? Commented Oct 8, 2013 at 7:26
  • 1
    Got it! I used Concat()
    – Duffer
    Commented Apr 12, 2019 at 5:11

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.