Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Panv
Contributor II
Contributor II

Count If in Group by Help

Hi

I have a table with IDs and various statuses associated to those IDs. Some statuses are known as "final statuses" but there is no column signifying this.

A final status can either be approved, rejected, or expired.

I want to count how many times each ID goes through a Final Status.

Here is what table currently looks like:

IDStatusUpdate Time
123Pending1/1/2020
123Expired1/30/2020
123Approved2/4/2020
456Pending1/4/2020
456Rejected1/16/2020
789Pending1/24/2020


And here is what i need it to look like:

IDCount of Final Status
1232
4561
789 

 

I know i would have to do a group by but confused how to proceed, given that I'm counting for various items in the same field. any help would be appreciated, thanks!

4 Replies
lironbaram
Partner - Master III
Partner - Master III

hi 

for this the best approach will be to add a new field in your load script 

the field will be added using this expression 

if (match(Status,'approved', 'rejected', 'expired')>0,1,0) as FinalStatusFlag 

then you will use a simple function in your table 

sum(FinalStatusFlag)

but you can also use this expression in the table directly

sum(if (match(Status,'approved', 'rejected', 'expired')>0,1,0))

 

usamabinsadiq
Contributor III
Contributor III

Hi,

you can use set analysis for this like:

Count({$<Status={'Expired','Approved','Rejected'}>} Status)

hope this help.

 

Regards,

if my replay helped you then please press like button and do not forget to press the "Accept as Solution" button.
Brett_Bleess
Former Employee
Former Employee

You have received two replies, please be sure to close out your thread by using the Accept as Solution button on the reply that helped you with your question.  If you did something different, you can post that and then use the button to mark that.  This provides the posters credit for the help and lets the other Members know what worked for the use case.  Please be sure to return to the thread and close it out if possible, it is greatly appreciated.

Regards,
Brett

To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.
Saravanan_Desingh

One solution:

tab1:
LOAD ID, Count(If(Match(Status,'Approved', 'Rejected', 'Expired'),ID)) As [Count of Final Status]
Group By ID
;
LOAD * INLINE [
    ID, Status, Update Time
    123, Pending, 1/1/2020
    123, Expired, 1/30/2020
    123, Approved, 2/4/2020
    456, Pending, 1/4/2020
    456, Rejected, 1/16/2020
    789, Pending, 1/24/2020
];

commQV33.PNG