Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Difference between two expressions

test:

load * Inline

[

  Test_A, Test_B, Test_C

  10.001, 20, 1

  31, 1, 2

];

QUALIFY * ;

test_1:

load sum(Test_A) - sum(Test_B) as TOTAL

Resident test

group by Test_C;

test_2:

load sum(Test_A - Test_B) as TOTAL

Resident test

group by Test_C;

Is there a difference in this two differents ways to calculate sum ?

(In my example this is exactly the same, but in my application with huges datas there are difference and I think is due to this calculation)

Thanks

1 Solution

Accepted Solutions
whiteline
Master II
Master II

Hi.

In some cases they can give different results.

Suppose that for some records the Test_B is null(). Then the second expression  will skip the whole record even if the Test_A is not null, because Test_A - null() = null()

View solution in original post

3 Replies
whiteline
Master II
Master II

Hi.

In some cases they can give different results.

Suppose that for some records the Test_B is null(). Then the second expression  will skip the whole record even if the Test_A is not null, because Test_A - null() = null()

maxgro
MVP
MVP

maybe if you have some null in your application data

result

1.png

script

test:

load rowno() as id, Test_A, if(Test_B='-',null(),Test_B) as Test_B, Test_C;

load * Inline

[

  Test_A, Test_B, Test_C

  100, 10, 1

  100, 1, 2

  100,-,1

];

QUALIFY * ;

test_1:

load Test_C, sum(Test_A) - sum(Test_B) as TOTAL

Resident test

group by Test_C;

test_2:

load Test_C, sum(Test_A - Test_B) as TOTAL

Resident test

group by Test_C;

SunilChauhan
Champion
Champion

first expression is f sum of differnce

where as second is difference of sum

Sunil Chauhan