Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sum fields in load script

I want to sum the values in several fields into one "sum" field.  Here's what I have so far:

LOAD customerID,

product1purchases,

product2purchases,

product3purchases,

(product1purchases+product2purchases+product3purchases) as totalpurchases

from

;

The line in bold doesn't work.  I tried using sum() and that didn't work either.  I know how to do this in a chart, but I want to do this in the load script if at all possible.

I feel like I'm missing something obvious.  Any ideas?

1 Solution

Accepted Solutions
Not applicable
Author

Hi Sophia, In this case Rangesum would be more appropriate.

PFA the example.

View solution in original post

4 Replies
Not applicable
Author

PFA. It should work fine. Can you send me your script please?

Not applicable
Author

That helped!  I tested it and found that most of the fields had null values and these were tripping it up.  If anyone reads this and has the same issue, here's what my solution was:

LOAD customerID,

product1purchases,

product2purchases,

product3purchases,

(if(product1purchases=1,product1purchases,0)

     +if(product2purchases=1,product2purchases,0)

     +if(product3purchases=1,product3purchases,0)) as totalpurchases

from

;

Not applicable
Author

Hi Sophia, In this case Rangesum would be more appropriate.

PFA the example.

Not applicable
Author

Even better, thanks!