Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
sumeet-vaidya
Partner - Creator
Partner - Creator

Calculate First Instance in Set Anlaysis

Dear all,

Please find below scenario where need to count no. of policices day wise.

Input     

PolicyNoStatusDateIssue Date
1001A1/8/20171/1/2017
1001B1/2/20171/1/2017
1001B1/3/20171/1/2017
1001A1/1/20171/1/2017
1001B1/5/20171/1/2017
1002A1/3/20171/1/2017
1002B1/2/20171/1/2017
1003A1/1/20171/1/2017
1004A1/1/20171/1/2017


Need to Pick the count of the Policy for the first instance of its Status w.r.t Issue Date


Output   

Issue DateTotal CountCount ACount B
1/1/2017431


stalwar1


Regards

Sumeet


1 Solution

Accepted Solutions
sunny_talwar

Or this

=Count(DISTINCT {<Flag = {1}>} PolicyNo)

Where Flag is created in the script like this

Table:

LOAD * INLINE [

    PolicyNo, Status, Date, Issue Date

    1001, A, 1/8/2017, 1/1/2017

    1001, B, 1/2/2017, 1/1/2017

    1001, B, 1/3/2017, 1/1/2017

    1001, A, 1/1/2017, 1/1/2017

    1001, B, 1/5/2017, 1/1/2017

    1002, A, 1/3/2017, 1/1/2017

    1002, B, 1/2/2017, 1/1/2017

    1003, A, 1/1/2017, 1/1/2017

    1004, A, 1/1/2017, 1/1/2017

];


Left Join (Table)

LOAD [Issue Date],

[PolicyNo],

Min(Date) as Date,

1 as Flag

Resident Table

Group By [Issue Date], [PolicyNo];

View solution in original post

4 Replies
sunny_talwar

Try this

=Sum(Aggr(If(Date = Min(TOTAL <PolicyNo, [Issue Date]> Date), 1, 0), [Issue Date], PolicyNo, Status, Date))

sunny_talwar

Or this

=Count(DISTINCT {<Flag = {1}>} PolicyNo)

Where Flag is created in the script like this

Table:

LOAD * INLINE [

    PolicyNo, Status, Date, Issue Date

    1001, A, 1/8/2017, 1/1/2017

    1001, B, 1/2/2017, 1/1/2017

    1001, B, 1/3/2017, 1/1/2017

    1001, A, 1/1/2017, 1/1/2017

    1001, B, 1/5/2017, 1/1/2017

    1002, A, 1/3/2017, 1/1/2017

    1002, B, 1/2/2017, 1/1/2017

    1003, A, 1/1/2017, 1/1/2017

    1004, A, 1/1/2017, 1/1/2017

];


Left Join (Table)

LOAD [Issue Date],

[PolicyNo],

Min(Date) as Date,

1 as Flag

Resident Table

Group By [Issue Date], [PolicyNo];

sumeet-vaidya
Partner - Creator
Partner - Creator
Author

Thanks Sunny. Works fine

sunny_talwar

Just fine? I wish it worked better .... I am glad that it worked out

Best,

Sunny