Skip to main content
Announcements
Applications are open for the 2024 Qlik Luminary Program. Apply by December 15 here.
cancel
Showing results for 
Search instead for 
Did you mean: 
wunderch
Creator
Creator

Update "Date until" with new "Date from" -1

Hi guys,

I have a straight table with RecordNo, product, Date from and Date until.

RecordNoproductDate fromDate until
1A08.06.202131.12.9999
2B08.06.202131.12.9999
3C08.06.202131.12.9999
4A15.06.202131.12.9999
5B15.06.202131.12.9999
6A18.06.202131.12.9999
    

 

Now I want to do:

If a product have a new entry with a newer "Date from", I want to update the "Date until" in the row before with the "Date from" -1 from the newer row. So that I get the following table:

RecordNoproductDate fromDate until
1A08.06.202114.06.2021
2B

08.06.2021

14.06.2021
3C08.06.202131.12.9999
4A15.06.202117.06.2021
5B15.06.202131.12.9999
6A18.06.202131.12.9999

 

I hope, you understand what I mean.

Any ideas?

Kindly regards

Chris

1 Solution

Accepted Solutions
Taoufiq_Zarra

@wunderch  you can use :

Tmp:

LOAD * INLINE [
    RecordNo, product, Date from, Date until
    1, A, 08.06.2021, 31.12.9999
    2, B, 08.06.2021, 31.12.9999
    3, C, 08.06.2021, 31.12.9999
    4, A, 15.06.2021, 31.12.9999
    5, B, 15.06.2021, 31.12.9999
    6, A, 18.06.2021, 31.12.9999
];
left join 

load product, count([Date from]) as CTmp resident Tmp group by product;

output:
noconcatenate

load RecordNo, product, [Date from],if(product=peek(product) and CTmp>1,Date(peek([Date from])-1),[Date until]) as [Date until];
load * resident Tmp order by product,[Date from] DESC;

drop table Tmp;

 

output:

Taoufiq_Zarra_0-1623227039667.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉

View solution in original post

5 Replies
Taoufiq_Zarra

@wunderch  in load script ?

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
wunderch
Creator
Creator
Author

Yes, I want to do this in load scrpt.

pabloviera
Creator
Creator

Hello Wunderch,

one approach could be doing a resident load of your data, sorting it by product and "Date from" descending (And no concatente of course)

Then use the previous function to change de "Date Until" in the next entry of the same product

Something like this (You can ignore the date interpretation function,I had to use it because my default dates are different)

NoConcatenate
EntriesOrdered:
Load
RecordNo as RN,
product as prod,
"Date from" as DateF,
if(Previous(product)=product,date(date#(previous("Date from"),'DD.MM.YYYY')-1,'DD.MM.YYYY'), "Date until") as DateU
Resident Entries order by product, "Date from" desc;

 

Regards

Taoufiq_Zarra

@wunderch  you can use :

Tmp:

LOAD * INLINE [
    RecordNo, product, Date from, Date until
    1, A, 08.06.2021, 31.12.9999
    2, B, 08.06.2021, 31.12.9999
    3, C, 08.06.2021, 31.12.9999
    4, A, 15.06.2021, 31.12.9999
    5, B, 15.06.2021, 31.12.9999
    6, A, 18.06.2021, 31.12.9999
];
left join 

load product, count([Date from]) as CTmp resident Tmp group by product;

output:
noconcatenate

load RecordNo, product, [Date from],if(product=peek(product) and CTmp>1,Date(peek([Date from])-1),[Date until]) as [Date until];
load * resident Tmp order by product,[Date from] DESC;

drop table Tmp;

 

output:

Taoufiq_Zarra_0-1623227039667.png

 

Regards,
Taoufiq ZARRA

"Please LIKE posts and "Accept as Solution" if the provided solution is helpful "

(you can mark up to 3 "solutions") 😉
wunderch
Creator
Creator
Author

Yes, it works!!!!! That's exactly what I want!!!!

Many thanks for your reply, you made my day!!!

Regards 

Chris