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: 
Anonymous
Not applicable

Load previous / peek ???

Hi all,

I have the following table (this is a reduced table in reality this table has more columns):

ServiceOrders
ServiceordernrOrderdateSerialnumberResource
REP93944413-11-2009123-456-789A
REP94643111-01-2010123-456-789B
REP95033004-02-2010123-456-789A

We are looking for repeated service orders for the same serial number. It is a repeated serviceorder if the orderdate is less than 6 months ago.


ServiceOrderRepeat:
LOAD *,
IF (
([Serialnumber] = previous ([Serialnumber])) and
Serviceordernr <> previous(Serviceordernr) and
(addmonths(Orderdate_origineel, -6) < previous (Orderdate)),
1,0) as RepeatCounter,
LOAD
Serviceordernr,
Serialnumber,
Orderdate
RESIDENT ServiceOrders
ORDER BY Serialnumber, Serviceordernr, Orderdate;


This results in:

ServiceOrderRepeat
ServiceordernrOrderdateSerialnumberRepeatCounter
REP93944413-11-2009123-456-7890
REP94643111-01-2010123-456-7891
REP95033004-02-2010123-456-7891


But I also want a counter the other way around, I want to see the following

ServiceOrderRepeat
ServiceordernrOrderdateSerialnumberRepeatCounterRepeatCounter 2
REP93944413-11-2009123-456-78901
REP94643111-01-2010123-456-78911
REP95033004-02-2010123-456-78910


I also want to have the sum of the last 6 months when selecting a month.

e.g. I select february, I want the REP950330 to have a total repeat counter of 2 ... at this moment I only have 1 ... but I need the sum of the last 6 months for the Serviceordernr.

Anyone has suggestions?

1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

Fixed this using the following join with desc load
<blockquote><pre>
ServiceOrderRepeat:
LOAD *,
IF (
([Serialnumber] = previous ([Serialnumber])) and
Serviceordernr <> previous(Serviceordernr) and
(addmonths(Orderdate_origineel, -6) < previous (Orderdate)),
1,0) as RepeatCounter,
LOAD
Serviceordernr,
Serialnumber,
Orderdate
RESIDENT ServiceOrders
ORDER BY Serialnumber, Orderdate, Serviceordernr;
JOIN

LOAD *,
IF (
([Serialnumber] = previous ([Serialnumber])) and
Serviceordernr <> previous(Serviceordernr) and
(addmonths(Orderdate_origineel, -6) < previous (Orderdate)),
1,0) as RepeatCounter,
LOAD
Serviceordernr,
Serialnumber,
Orderdate
RESIDENT ServiceOrders
ORDER BY Serialnumber, Orderdate DESC, Serviceordernr;


View solution in original post

2 Replies
Anonymous
Not applicable
Author

Did try to use Peek(Serialnumber , 1) to see if the next item had the same serial number to retrieve the RepeatCounter 2 but this gives an empty value ...

Any ideas??

Anonymous
Not applicable
Author

Fixed this using the following join with desc load
<blockquote><pre>
ServiceOrderRepeat:
LOAD *,
IF (
([Serialnumber] = previous ([Serialnumber])) and
Serviceordernr <> previous(Serviceordernr) and
(addmonths(Orderdate_origineel, -6) < previous (Orderdate)),
1,0) as RepeatCounter,
LOAD
Serviceordernr,
Serialnumber,
Orderdate
RESIDENT ServiceOrders
ORDER BY Serialnumber, Orderdate, Serviceordernr;
JOIN

LOAD *,
IF (
([Serialnumber] = previous ([Serialnumber])) and
Serviceordernr <> previous(Serviceordernr) and
(addmonths(Orderdate_origineel, -6) < previous (Orderdate)),
1,0) as RepeatCounter,
LOAD
Serviceordernr,
Serialnumber,
Orderdate
RESIDENT ServiceOrders
ORDER BY Serialnumber, Orderdate DESC, Serviceordernr;