Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

PROBLEM - Math Adding On Script Brings Wrong Result

My script has this syntax:

CALCULATED_LINE_COSTS:

  load  [ID],

   COST_GAS,  COST_DEPR,  COST_MAIN,  COST_HWY,  COST_ADMIN, COST_SALARY,

  (COST_GAS + COST_DEPR + COST_MAIN + COST_HWY + COST_ADMIN + COST_SALARY) As  [TOTAL_COST]

  resident  table_10_3;

 

===========================

In qlikview pivot chart, i have an expression- SUM(TOTAL_COST)

The result of it is wrong!

If I create expression summing all costs like this- SUM(COST_GAS) + SUM(COST_DEPR) + ..... and so on.

The result is correct.

Why is the script adding won't work.

Help!!

1 Solution

Accepted Solutions
Not applicable

Re: PROBLEM - Math Adding On Script Brings Wrong Result

Hi,

Your fields may contain null values.

Try using Alt(COST_GAS, 0) + Alt(COST_DEPR, 0) + etc... as TOTAL_COST.

3 Replies
Not applicable

Re: PROBLEM - Math Adding On Script Brings Wrong Result

Hi,

Your fields may contain null values.

Try using Alt(COST_GAS, 0) + Alt(COST_DEPR, 0) + etc... as TOTAL_COST.

MVP
MVP

Re: PROBLEM - Math Adding On Script Brings Wrong Result

Yes, using arithmetic operator + with NULL operands will result in NULL. Use rangesum(FIELD1,FIELD2,...) instead if you want to handle NULL as zero.

Not applicable

Re: PROBLEM - Math Adding On Script Brings Wrong Result

I'm Grateful..

Community Browser