Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Am I able to group dates together based on number of days between dates?

I'm doing some work on customer calls to calculate repeat calls and need to apply some logic where if they call within 5 days of previous call, the calls are considered as related and just need 1 record and calc the number of repeated called within the period.

See example below

Customer ID

Call DateCount
12301-05-20141
12302-05-20141
12306-05-20141
12308-05-20141
12314-05-20141
12401-05-20141
12403-05-20141
12404-05-20141
12410-05-20141

So we are checking by customer where there has been a gap of 5 days or more in calls and grouping accordingly.The table above would become:-

Customer IDCall DateCall CountRepeat Calls Exist?
12301-05-20144Y
12314-05-20141N
12401-05-20143Y
12410-05-20141N

Note that the Call Date in the 2nd table is now just the min date from the grouped data. Am I able to do this in Qlikview?

1 Solution

Accepted Solutions
MarcoWedel

Hi,

QlikCommunity_Thread_129902_Pic1.JPG.jpg

tabCalls:

LOAD [Customer ID],

    [Call Date] as [Call Dates]

FROM [http://community.qlik.com/thread/129902]

(html, codepage is 1252, embedded labels, table is @1);

tabCallCount:

LOAD [Customer ID],

    Alt(If([Customer ID] = Previous([Customer ID]) and [Call Dates] <= Previous([Call Dates])+5, Peek(CallID), Peek(CallID)+1), 1) as CallID,

    [Call Dates]

Resident tabCalls

Order by [Customer ID], [Call Dates];

Left Join (tabCallCount)

LOAD *, If([Call Count]>1, 'Y', 'N') as [Repeat Calls Exist];

LOAD [Customer ID],

    CallID,

    Count(CallID) as [Call Count],

    Date(Min([Call Dates])) as [Call Date]

Resident tabCallCount

Group By [Customer ID], CallID;

hope this helps

regards

Marco

View solution in original post

3 Replies
marcus_sommer

You could do it within a by Customer ID and Call Date sorted (resident) load and using peek() or previous() to look in the previous data-rows and check these values against each other, example:

t1:

Load

     *,

     if(rowno() = 1, 1,

     if([Customer ID] = peek("Customer ID", -1) and

          [Call Date] - peek("Call Date", -1) <= 5, peek("Call Count", -1) + 1, 1) as [Call Count]

Resident abc;

Maybe you need a little bit more of check-logic but generally this will work.

- Marcus

MarcoWedel

Hi,

QlikCommunity_Thread_129902_Pic1.JPG.jpg

tabCalls:

LOAD [Customer ID],

    [Call Date] as [Call Dates]

FROM [http://community.qlik.com/thread/129902]

(html, codepage is 1252, embedded labels, table is @1);

tabCallCount:

LOAD [Customer ID],

    Alt(If([Customer ID] = Previous([Customer ID]) and [Call Dates] <= Previous([Call Dates])+5, Peek(CallID), Peek(CallID)+1), 1) as CallID,

    [Call Dates]

Resident tabCalls

Order by [Customer ID], [Call Dates];

Left Join (tabCallCount)

LOAD *, If([Call Count]>1, 'Y', 'N') as [Repeat Calls Exist];

LOAD [Customer ID],

    CallID,

    Count(CallID) as [Call Count],

    Date(Min([Call Dates])) as [Call Date]

Resident tabCallCount

Group By [Customer ID], CallID;

hope this helps

regards

Marco

MarcoWedel

if your input table is already sorted like in this case, you can also try with:

tabCalls:

LOAD [Customer ID],

    [Call Date] as [Call Dates],

    Alt(If([Customer ID] = Previous([Customer ID]) and [Call Date] <= Previous([Call Date])+5, Peek(CallID), Peek(CallID)+1), 1) as CallID

FROM [http://community.qlik.com/thread/129902]

(html, codepage is 1252, embedded labels, table is @1);

tabCallCount:

LOAD *, If([Call Count]>1, 'Y', 'N') as [Repeat Calls Exist];

LOAD [Customer ID],

    Count(CallID) as [Call Count],

    Date(Min([Call Dates])) as [Call Date]

Resident tabCalls

Group By [Customer ID], CallID;

QlikCommunity_Thread_129902_Pic2.JPG.jpg

QlikCommunity_Thread_129902_Pic3.JPG.jpg

hope this helps

regards

Marco