Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Aggr with If help needed

Hi,

I am trying to sum the number of calls in a job if the sum of the number of answer machines is 0. The formula that I have at the moment is

sum(if(aggr(sum(AnsMachine),JobNumber)>0,0,aggr(sum(Calls),JobNumber)))



but this is incorrect. The first point of this sums the answer machines, grouped by job, then checks if this is greater than 0 and if it is sets the result to 0, if the sum is 0 then is sums the calls over the same job numbers.

Any ideas where I am going wrong? I have attached a sample qvd which should help explain.

1 Solution

Accepted Solutions
Not applicable
Author

Hi All,

Thanks for the help. Although not exactly what I wanted I waas able to use the different suggestions to get to the answer (although I'm not totally sure why it is the answer. The final solution is below.

sum(aggr(if(aggr(sum(AnsMachine),JobNumber)=0,aggr(sum(Calls),JobNumber),aggr(sum(AnsMachine*0.1)+sum(Calls),JobNumber)),JobNumber))



You may notice that it is a little more complicated than the original, where the sum of answer machines is 0 I want one formula, where it is not 0 I want another.

Thanks for you help.

View solution in original post

4 Replies
Not applicable
Author

Hi.

test





sum(if(aggr(sum(AnsMachine),JobNumber)=0,aggr(sum(Calls),JobNumber),0))

Regards

Anders



gandalfgray
Specialist II
Specialist II

or you can try:


if(aggr(sum(AnsMachine),JobNumber)=0, aggr(sum(Calls),JobNumber), 0)


Not applicable
Author

I have found that performance takes a hit the more IF statements you have within the sum. However, Sum (if x=y,y) seems to run better than if(x=y,sum(y)). They don't work exacly the same way.

Not applicable
Author

Hi All,

Thanks for the help. Although not exactly what I wanted I waas able to use the different suggestions to get to the answer (although I'm not totally sure why it is the answer. The final solution is below.

sum(aggr(if(aggr(sum(AnsMachine),JobNumber)=0,aggr(sum(Calls),JobNumber),aggr(sum(AnsMachine*0.1)+sum(Calls),JobNumber)),JobNumber))



You may notice that it is a little more complicated than the original, where the sum of answer machines is 0 I want one formula, where it is not 0 I want another.

Thanks for you help.