Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

intermediate aggregation without setting nulls to zero

I have some raw data that needs to be aggregated by "id" which is not a dimension in the chart, and then summed with the absolute of val and val2  individually. The concept is sum of absolute of individual values is not the same as absolute (sum(values)). Some Id's have zero value and null values. Null indicates that that id should not be counted.

 

gr adate id val val2
A'11/18/2015'15-5
A'11/17/2015'2-23
A'11/17/2015'25-5
A'11/16/2015'303
A'11/13/2015'5-66
A'11/11/2015'6Null-2
A'11/10/2015'71-1
B'11/18/2015'17-7
B'11/17/2015'2-9Null
B'11/17/2015'24Null
B'11/13/2015'3-80
B'11/13/2015'370
B'11/13/2015'3110
B'11/12/2015'4Null-6

For group A, it should report cnt=numericcount(id)=5 and sum(fabs(val))=15 and not 19, because for id=2 fabs(val)=fabs(-2+5)=3.

Possible solutions:

1. on raw data cnt=numericcount(id) will work. But sum will not

2. if I do load from resident with a group by then null becomes zero, I lose the count but sum is okay.

Thanks.

1 Solution

Accepted Solutions
Not applicable
Author

Thank you all of you mighty guys, in particular, maxgro for the correct suggestion for Count() issue, swuehl and Sunny T for the Sum() issue.

The right combination is

Count(distinct  if(val<>'Null', id))

and

=Sum( Aggr( Fabs(Sum(val)), gr, id)) // same result

or

=Sum( Aggr( Fabs(Sum(val)), id, gr)) //same result


View solution in original post

7 Replies
swuehl
MVP
MVP

You want to do this in the script or chart?

In a chart with dimension gr, maybe like

=Sum( Aggr( Fabs(Sum(val)), gr, id))

sunny_talwar

These may be:

=Count({<Key = {"=Avg(fabs(val)) > 0"}>}id)

=Sum(Aggr(fabs(Sum(val)), id, gr))


Capture.PNG

Not applicable
Author

The count for B needs to be 3, because ids are 1,2, 3 and 4 but 4 has val=Null.

The data can have multiple rows of 4 with Null.

also the average sum of 0 is valid, so cannot exclude them.

I tried several things. It seems that we do aggr() on id/gr  then exclude sum that equals Null. But I think sum considers Null to be zero, that is another issue.

Thanks for the help

Not applicable
Author

I thought the following  would work, but returns 0 --

count(  Aggr( Fabs(Sum({${<val-={'Null'}>} val)), gr, id))

sunny_talwar

What are you hoping to see for count and Sum for both A and B?

maxgro
MVP
MVP

maybe a

Count(distinct  if(val<>'Null', id))

Not applicable
Author

Thank you all of you mighty guys, in particular, maxgro for the correct suggestion for Count() issue, swuehl and Sunny T for the Sum() issue.

The right combination is

Count(distinct  if(val<>'Null', id))

and

=Sum( Aggr( Fabs(Sum(val)), gr, id)) // same result

or

=Sum( Aggr( Fabs(Sum(val)), id, gr)) //same result