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

Announcements
Save $650 on Qlik Connect, Dec 1 - 7, our lowest price of the year. Register with code CYBERWEEK: Register
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Problem with Grouped Count

Hi, I am having a hard time trying to make a column to show a particular Count, here is the scenario:

I need to count the unique ContactID's that meet the following criterias:

  1. One of it's ContactDirection must be 1
  2. One of it's IsInQueue must be 1
  3. One of it's ReskillIndicator must be 0 or 1
  4. One of it's IsAbandon must not be 1

After these filters have been met, then check the total of the sum of its ContactDuration values and compare it against a variable, IF all this is met, then count it.

I have the following data, it has 5 ContactId's just 2 of them should be counted.

ContactIDIsInQueueContactDirectionContactDurationReskillIndicatorIsAbandonVALID
310012100001
310012001
31001121197001
3100121301
31002171
310021351101
31002171
31010113730
3101011800
310101161400
31010135000
310101134230
310101119240
310101300
31011242970
31011260630
310112119240
310112460
310121111400
3101211111900
310121156700
310121125960
31012162970
31012122330
31012132200
31012100


So far i have came up with a formula that is now returning if the current ContactID is valid, but when i try to compare the sum against the variable it returns all 1's so no further Aggr can be done on it:

//if(


if(
sum(
{1
<
ContactID = P({1<ContactDirection={1}>} ContactID)
* P({1<IsInQueue={1}>} ContactID)
* P({1<ReskillIndicator={"<=1"}>} ContactID)
* E({1<IsAbandon={1}>} ContactID)
,IsInQueue = {1}
>
} ContactDuration
)
, 1,0)

//<=(ServiceLevelAgreement*1000), 1)

I have commented the 1st and last lines because here is were I am stuck now.

The result is the following right now:

ContactIDTEST
310010
310020
310101
310110
310121
1


But i want it to be:

ContactIDTEST
310010
310020
310102
310110
310122
2


Can someone please take a look at it and throw in any suggestion?

Thanks in advance for your time.

-Ed

16 Replies
vgutkovsky
Master II
Master II

No, the outer sum, not the inner sum--put the set analysis on the sum that encloses the aggr. If that doesn't work, can you repost your original table but the Start date column so I can see what it looks like?

Regards,

Not applicable
Author

Worked perfectly Vlad, thank you very much, this was the final version of the expression, the requirement changed, so no longer the total must be shown in all the filtered ContactID's

sum(
{<ContactStartDate={">=$(=num(varCalendarStartDate))<$(=num(varCalendarEndDate))"}>}
aggr(
if(
ContactDirection=1
and max(IsInQueue)=1
and len(trim(max(ReskillIndicator)))>0
and min(IsAbandon)<>1
and sum({<IsInQueue={1}>} ContactDuration) <=(ServiceLevelAgreement*1000)
,
1
)
, ContactID
)
)


vgutkovsky
Master II
Master II

So now the output should be:

310010
310020
310101
310110
310121


?

Not applicable
Author

Yes you are right, thanks again for all you time on this.

Regards

-Ed

vgutkovsky
Master II
Master II

Actually, that makes the whole expression easier:


sum({<ContactStartDate={">=$(=num(varCalendarStartDate))<$(=num(varCalendarEndDate))"}>}
aggr(
if(ContactDirection=1 and max(IsInQueue)=1 and len(trim(max(ReskillIndicator)))>0 and min(IsAbandon)<>1 and sum({<IsInQueue={1}>} ContactDuration) <= (ServiceLevelAgreement*1000),
1
)
,ContactID
)
)


Regards,

Not applicable
Author

Hi Vlad, long time since you helped me to fix this.

Recently we deplyed our initial version of the QV document, and under heavy loads of data, we are seeing that this speciffic metric is hitting hard our CPU, we think AGGR is a costly operation, do you think the same? If so, do you think there is another way to pull this expression without using AGGR?

Regards.

-Ed

vgutkovsky
Master II
Master II

Hi, Ed. AGGR is definitely a very heavy operation. Unfortunately in your case there is no other way to do it given your current fields. That is because you need to do nested aggregation and that is only possible with AGGR. To improve performance, I would recommend moving a lot of the aggregation to the script and creating a flags that you can then check using set analysis. For example (in a Group By) you can check min(IsAbandon)<>1 and set a flag of 1 for instances where this is true.

Regards,