Skip to main content
Announcements
Global Transformation Awards! Applications are now open. Submit Entry
cancel
Showing results for 
Search instead for 
Did you mean: 
cpiocpio
Partner - Creator
Partner - Creator

Peek vs Previous - Use Last Number PLUS!!


Hi all

I am back.

After an excellent response yesterday, I thought thats one in the bag, move on, but no.

The requirement has been extended.

Still generating missing dates, and repeating previous values but PER machine

So in the attched, i have used INLINE and out in only a few rows, in 3 coloumns

LOAD * INLINE [
    DataDate, MachineName, Mileage
    02/06/2009,SW81AA,638
    04/06/2009,SW88AA,1600
    05/06/2009,SW88AA,1600
    07/06/2009,33KM85,309
]
;

The required OUTPUT is, that it should repeat per Machine Name per day :

02/06/2009;"SW81AA";638

03/06/2009;"SW81AA";638

04/06/2009;"SW81AA";638

04/06/2009;"SW88AA";1600

05/06/2009;"SW88AA";1600

05/06/2009;"SW81AA";638

06/06/2009;"SW88AA";1600

06/06/2009;"SW81AA";638

07/06/2009;"33KM85";309

07/06/2009;"SW88AA";1600

07/06/2009;"SW81AA";638

Many thanks

1 Solution

Accepted Solutions
Nicole-Smith

Looks like you already got your answer, but here is my fixed solution just in case:

Result:

LOAD * INLINE [

    DataDate, MachineName, Mileage

    02/06/2009,SW81AA,638

    04/06/2009,SW88AA,1600

    06/06/2009,SW88AA,1700

    07/06/2009,33KM85,309

];

Temp2:

load DataDate, MachineName, if(MachineName=previous(MachineName),previous(DataDate)) as NextDate, Mileage

Resident Result

order by MachineName, DataDate desc;

MaxDate:

Load max(DataDate) as MaxDate

Resident Temp2;

LET vMaxDate = PEEK('MaxDate', 0, 'MaxDate');

DROP TABLE MaxDate;

Concatenate(Result)

Load Date(DataDate + IterNo()) as DataDate, MachineName, Mileage

Resident Temp2

while if(len(NextDate)>0, DataDate + IterNo() < NextDate, DataDate + IterNo() <= $(vMaxDate));

drop Table Temp2;

View solution in original post

11 Replies
Nicole-Smith

I think this should do it:

Result:

LOAD * INLINE [

    DataDate, MachineName, Mileage

    02/06/2009,SW81AA,638

    04/06/2009,SW88AA,1600

    05/06/2009,SW88AA,1600

    07/06/2009,33KM85,309

];

Temp2:

load DataDate, MachineName, previous(DataDate) as NextDate, Mileage

Resident Result

order by DataDate desc;

MaxDate:

Load max(DataDate) as MaxDate

Resident Temp2;

LET vMaxDate = PEEK('MaxDate', 0, 'MaxDate');

DROP TABLE MaxDate;

Concatenate(Result)

Load Date(DataDate + IterNo()) as DataDate, MachineName, Mileage

Resident Temp2

while DataDate + IterNo() <= $(vMaxDate);

drop Table Temp2;

rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

Or use Qlikview Components - A script library for Qlikview development

Result:

LOAD * INLINE [

DataDate, MachineName, Mileage

02/06/2009,SW81AA,638

04/06/2009,SW88AA,1600

05/06/2009,SW88AA,1600

07/06/2009,33KM85,309

];

CALL Qvc.GetFieldValues('vStats', 'DataDate');

LET Qvc.ExpandInterval.v.RangeCeiling = vStats.Max;

CALL Qvc.ExpandInterval('Result', 'DataDate', '', 'MachineName');

CALL Qvc.Cleanup

-Rob

http://masterssummit.com

cpiocpio
Partner - Creator
Partner - Creator
Author

Hi Nicole

Good but not quite there, When a new value is supplied for an equipment type, then that is the value that should carry on, not OLD and new

It works up to a point until the
next reading is available then repeats new reading and old per day.

So you see when it gets to 21st, it starts repeating that days value but also repeats the earlier one

Input:


 

03/01/2014


 

 

02SE45


 

 

981


 

 

09/01/2014


 

 

02SE45


 

 

981


 

 

21/01/2014


 

 

02SE45


 

 

982


 

 

22/01/2014


 

 

02SE45


 

 

982


 

QV output:


 

03/01/2014
 


 

 

02SE45


 

 

981
 


 

 

04/01/2014
 


 

 

02SE45


 

 

981
 


 

 

05/01/2014
 


 

 

02SE45


 

 

981
 


 

 

06/01/2014
 


 

 

02SE45


 

 

981
 


 

 

07/01/2014
 


 

 

02SE45


 

 

981
 


 

 

08/01/2014
 


 

 

02SE45


 

 

981
 


 

 

09/01/2014
 


 

 

02SE45


 

 

981
 


 

 

10/01/2014
 


 

 

02SE45


 

 

981
 


 

 

11/01/2014
 


 

 

02SE45


 

 

981
 


 

 

12/01/2014
 


 

 

02SE45


 

 

981
 


 

 

13/01/2014
 


 

 

02SE45


 

 

981
 


 

 

14/01/2014
 


 

 

02SE45


 

 

981
 


 

 

15/01/2014
 


 

 

02SE45


 

 

981
 


 

 

16/01/2014
 


 

 

02SE45


 

 

981
 


 

 

17/01/2014
 


 

 

02SE45


 

 

981
 


 

 

18/01/2014
 


 

 

02SE45


 

 

981
 


 

 

19/01/2014
 


 

 

02SE45


 

 

981
 


 

 

20/01/2014
 


 

 

02SE45


 

 

981
 


 

 

21/01/2014
 


 

 

02SE45


 

 

981
 


 

 

21/01/2014
 


 

 

02SE45


 

 

982
 


 

 

22/01/2014
 


 

 

02SE45


 

 

981


 

 

22/01/2014
 


 

 

02SE45


 

 

982


 

 

23/01/2014
 


 

 

02SE45


 

 

981


 

 

23/01/2014
 


 

 

02SE45


 

 

982


 

 

24/01/2014
 


 

 

02SE45


 

 

981


 

 

24/01/2014
 


 

 

02SE45


 

 

982


 

 

25/01/2014
 


 

 

02SE45


 

 

981


 

 

25/01/2014
 


 

 

02SE45


 

 

982


 

 

26/01/2014
 


 

 

02SE45


 

 

981


 

 

26/01/2014
 


 

 

02SE45


 

 

982


 

 

27/01/2014
 


 

 

02SE45


 

 

981


 

 

27/01/2014
 


 

 

02SE45


 

 

982


 

 

28/01/2014
 


 

 

02SE45


 

 

981


 

 

28/01/2014
 


 

 

02SE45


 

 

982


 

 

29/01/2014
 


 

 

02SE45


 

 

981


 

 

29/01/2014
 


 

 

02SE45


 

 

982


 

 

30/01/2014
 


 

 

02SE45


 

 

981


 

 

30/01/2014
 


 

 

02SE45


 

 

982


 

 

31/01/2014
 


 

 

02SE45


 

 

981


 

 

31/01/2014
 


 

 

02SE45


 

 

982


 

 

01/02/2014
 


 

 

02SE45


 

 

981


 

 

01/02/2014
 


 

 

02SE45


 

 

982


 

 

02/02/2014
 


 

 

02SE45


 

 

981


 

 

02/02/2014
 


 

 

02SE45


 

 

982


 

 

03/02/2014
 


 

 

02SE45


 

 

981


 

 

03/02/2014
 


 

 

02SE45


 

 

982


 

 

04/02/2014
 


 

 

02SE45


 

 

981


 

 

04/02/2014
 


 

 

02SE45


 

 

982


 

 

05/02/2014
 


 

 

02SE45


 

 

981


 

 

05/02/2014
 


 

 

02SE45


 

 

982


 

 

06/02/2014
 


 

 

02SE45


 

 

981


 

 

06/02/2014
 


 

 

02SE45


 

 

982


 

 

07/02/2014
 


 

 

02SE45


 

 

981


 

 

07/02/2014
 


 

 

02SE45


 

 

982


 

 

08/02/2014
 


 

 

02SE45


 

 

981


 

 

08/02/2014
 


 

 

02SE45


 

 

982


 

 

09/02/2014
 


 

 

02SE45


 

 

981


 

 

09/02/2014
 


 

 

02SE45


 

 

982


 

 

10/02/2014
 


 

 

02SE45


 

 

981


 

 

10/02/2014
 


 

 

02SE45


 

 

982


 

 

11/02/2014
 


 

 

02SE45


 

 

981


 

 

11/02/2014
 


 

 

02SE45


 

 

982


 

Not applicable

As an exercice, I did the job yesterday but did not send you (there were many answers already)

It may help you

There is also a very interesting post by HIC about generating missing data.

Fabrice

cpiocpio
Partner - Creator
Partner - Creator
Author

Hi Aunez

Many thanks for this, it is looking promising.

Nice to have some comments in the script, to "guide us newbies"

Just pointed at some real data, and thats looks good to me to.

Now passed over to end user to check, will advise

Many thanks again

Mike


Not applicable

I had modified some your data to make more tests

But you will enter real data when tests are ok

Fabrice

Nicole-Smith

Looks like you already got your answer, but here is my fixed solution just in case:

Result:

LOAD * INLINE [

    DataDate, MachineName, Mileage

    02/06/2009,SW81AA,638

    04/06/2009,SW88AA,1600

    06/06/2009,SW88AA,1700

    07/06/2009,33KM85,309

];

Temp2:

load DataDate, MachineName, if(MachineName=previous(MachineName),previous(DataDate)) as NextDate, Mileage

Resident Result

order by MachineName, DataDate desc;

MaxDate:

Load max(DataDate) as MaxDate

Resident Temp2;

LET vMaxDate = PEEK('MaxDate', 0, 'MaxDate');

DROP TABLE MaxDate;

Concatenate(Result)

Load Date(DataDate + IterNo()) as DataDate, MachineName, Mileage

Resident Temp2

while if(len(NextDate)>0, DataDate + IterNo() < NextDate, DataDate + IterNo() <= $(vMaxDate));

drop Table Temp2;

Not applicable

Mike,


Is it OK ? closed ?

Fabrice