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: 
RichaU24
Contributor
Contributor

Counting based on date criteria

I am trying to generate distinct counts of policies that are active at a particular point in time.

My data looks Like this

Policy Number Start Date
p1 01-04-2013
P1 01-08-2013
p2 30-08-2013
p2 01-04-2014
p3 30-06-2014
P2 01-08-2014
P1 07-04-2015
P3 30-06-2015
P2 01-08-2015
P1 07-04-2016
p5 30-06-2016

 

A policy remains active for 1 year from the start date unless a different start date comes up before a full year is complete.

I want to summarize this in the following way. 

Period  Number of Policies active
Feb-13
May-15 3 (p1,p2,p3)
Aug-16 2 (p1,p5)

 

Can somebody pls suggest the way to go about it? 

Thanks

 

Labels (3)
2 Replies
vchuprina
Specialist
Specialist

Hi,

You should use concat function as in my example below:

 

DATA_TMP:
LOAD
[Policy Number],
[Start Date],
Date(Date#(Right([Start Date],7), 'MM-YYYY'), 'MMM-YYYY') AS [Month Year]
;
LOAD * Inline[
Policy Number, Start Date
p1, 01-04-2013
P1, 01-08-2013
p2, 30-08-2013
p2, 01-04-2014
p3, 30-06-2014
P2, 01-08-2014
P1, 07-04-2015
P3, 30-06-2015
P2, 01-08-2015
P1, 07-04-2016
p5, 30-06-2016
];

DATA:
LOAD
Count(DISTINCT[Policy Number])&' ('& Concat(DISTINCT [Policy Number], ', ')&')' AS [Number of Policies active],
[Month Year]
Resident DATA_TMP
Group By [Month Year];

DROP Table DATA_TMP;

 

Regards,

Vitalii

Press LIKE if the given solution helps to solve the problem.
If it's possible please mark correct answers as "solutions" (you can mark up to 3 "solutions").
vinieme12
Champion III
Champion III

or you could just do it in the chart directly,

this is more flexible to do in front end as selections could change possible values

=count(distinct [Policy Number]) & '('& concat(distinct [Policy Number],',') &')'

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.