Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
anushree1
Specialist II
Specialist II

How to sum Null Values

HI,

I would like to create a field in the script which returns Null(Meaning '-') incase i Perform Sum Function on top of it.

I tried the below ways to create the field but when sum is applied on the field it returns 0.

Eg:

'' As Test

Null() AS Test

'-' as Test

None of them return '-' instead they return 0 when sum is applied on it like Sum(Test)

Can anyone please let me know how this could be done, so that i get '-' as the result

4 Replies
prieper
Master II
Master II

In the script:

IF(SUM(MyValue) = 0, NULL(), SUM(MyValue)          AS ....

jonathandienst
Partner - Champion III
Partner - Champion III

Sum aggregates many values. QV skips over nulls, so if all the values are null, then Sum returns 0 as there was nothing to sum.

So do you want to show a null any value is null, or if all values are null?

Logic will get you from a to b. Imagination will take you everywhere. - A Einstein
anushree1
Specialist II
Specialist II
Author

i have a pick match expression which returns a field upon which i perform sum() in a chart.

so incase the pick match does'nt yield the right expression i want the sum() in chart to return '-'.

Please let me if this is not clear

el_aprendiz111
Specialist
Specialist

Hi,

2 options:

tmp:
LOAD *,
If(Len(Data) = 0,1,0) AS  MyNull,
If(Len(Data) = 0, RangeSum(1, Peek('CountNull')), RangeSum(0, Peek('CountNull'))) AS CountNull
;
Load * inline
[
ID   ,Data
1    ,123
2    ,23
3    ,
4    ,
5    ,
6    ,
7    ,453
8    ,143
9    ,1
10   ,
11   ,211
12   ,
13   ,
14   ,4892
]
;

countNull.png