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

1 Solution

Accepted Solutions
vgutkovsky
Master II
Master II

It seems a little bit strange to me that you want the total count on each ID. This makes the logic somewhat convoluted and much longer than it would need to be otherwise. A sample solution is attached.

Regards,

View solution in original post

16 Replies
vgutkovsky
Master II
Master II

Ed,

This shouldn't be too difficult to do, but a couple questions first:

  1. Do you need the count in the script or just in the front end?
  2. Why is the count 2 and not 1 for each of the ContactIDs?


Regards,

Not applicable
Author

Hi Vlad, thanks for taking a look at my issue, below my comments:

1- The result of this count() will be the value of a column that i'll later reference from another expression

2- I need that all records show the total from all the data, not filtered by the current selection, i tried to make this happen by using 1<{}> but couldnt make it work

vgutkovsky
Master II
Master II

It seems a little bit strange to me that you want the total count on each ID. This makes the logic somewhat convoluted and much longer than it would need to be otherwise. A sample solution is attached.

Regards,

Not applicable
Author

Thank you very much Vlad, tomorrow I'll try to use your fix and bring some joy to our office 🙂

Best Regards

Edgardo

Not applicable
Author

Vlad, looking closely, i see that you expression is grouping and filtering correctly, but there is just one piece missing in the puzzle, is that at the end i also need to sum contactDuration for these pre-filtered ContactID's and check if it is greater than a variable, can it be something like this?


if(rowno()<>0,
if(
ContactDirection=1
and max(IsInQueue)=1
and len(trim(max(ReskillIndicator)))>0
and min(IsAbandon)<>1
and sum(ContactDuration)>#SLA //New filter
,
1,
0
),
1
)


The thing is, that this final sum(ContactDuration) has to be against only the records that have inQueue = 1

Any ideas?

Thanks again for your time Vlad.

-Ed

vgutkovsky
Master II
Master II

Yep, you're close. You just need to add a bit of set analysis:

and sum({<IsInQueue={1}>} ContactDuration) > SLA


Regards,

Not applicable
Author

Thanks a lot Vlad, works like a charm, sorry for keep buggin you , but there is just one thing i coulndt get done, i need to further filter the ContactID's by a date variable, I have been trying but it seems like a have some sort of problem with this:


if(
ContactDirection=1
and max(IsInQueue)=1
and len(trim(max(ReskillIndicator)))>0
and min(IsAbandon)<>1
and sum({<IsInQueue={1}>} ContactDuration) <=(ServiceLevelAgreement*1000)
and ContactStartDate > num(varCalendarStartDate) > num(varCalendarEnd) // doesnt work
,
1
)


this new filter is that a date column, must fit between a range of 2 variables.

Any suggestions?

-Ed

vgutkovsky
Master II
Master II

You can't combine comparisons that way in QlikView. So you would need to use the following logic: and ContactStartDate > num(varCalendarStartDate) and ContactStartDate < num(varCalendarEnd) or something similar. If ContactStartDate is the same for all rows within the ContactID, then you can also just add the following set analysis to the outer sum: <ContactStartDate={">$(varCalendarStartDate)<$(varCalendarEnd)"}>

Regards,

Not applicable
Author

I tried your code, but didnt work:


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


The problem is that is not filtering further, i think the reason is because the ContactStartDate is not the same inside the ContactID context i tried a min() but didnt work too:


sum({<IsInQueue={1},Min(ContactStartDate)={">=$(=num(varCalendarStartDate))<$(=num(varCalendarEndDate))"}>} ContactDuration) <=(ServiceLevelAgreement*1000)


Any suggestion?

-Ed