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: 
komminenianusha
Partner - Contributor III
Partner - Contributor III

How to calculate EndDate base on startDate

Hi All,

I have a requirement to calculate ENDDate based on StartDate.

Find below details for reference

This table is input data

Load * inline [
Product,Discount,StartDate
Shoes,10,01/01/2020
Shoes,20,01/03/2020
Shoes,40,01/06/2020
Shirt,20,01/09/2020
Shirt,30,01/10/2020
Shirt,60,01/11/2020
];

Expected Output:

  Load * inline [
Product,Discount,StartDate,EndDate
Shoes,10,01/01/2020,29/02/2020
Shoes,20,01/03/2020,31/05/2020
Shoes,40,01/06/2020,
Shirt,20,01/09/2020,30/09/2020
Shirt,30,01/10/2020,05/11/2020
Shirt,60,06/11/2020,
];

Please anyone help me to achieve this.

1 Solution

Accepted Solutions
PrashantSangle

try below code,

 

Temp:
Load Product,Discount,Date(Date#(StartDate,'DD/MM/YYYY')) as StartDate inline [
Product,Discount,StartDate
Shoes,10,01/01/2020
Shoes,20,01/03/2020
Shoes,40,01/06/2020
Shirt,20,01/09/2020
Shirt,30,01/10/2020
Shirt,60,06/11/2020,
];

NoConcatenate
Temp1:
Load *,
if(Previous(Product)<> Product,'-',Date(Previous(StartDate)-1)) as nextDate
Resident Temp
order by StartDate desc;

Drop table Temp;

 

Thanks & Regards,

Prashant Sangle

https://predoole.com/

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂

View solution in original post

3 Replies
PrashantSangle

try below code,

 

Temp:
Load Product,Discount,Date(Date#(StartDate,'DD/MM/YYYY')) as StartDate inline [
Product,Discount,StartDate
Shoes,10,01/01/2020
Shoes,20,01/03/2020
Shoes,40,01/06/2020
Shirt,20,01/09/2020
Shirt,30,01/10/2020
Shirt,60,06/11/2020,
];

NoConcatenate
Temp1:
Load *,
if(Previous(Product)<> Product,'-',Date(Previous(StartDate)-1)) as nextDate
Resident Temp
order by StartDate desc;

Drop table Temp;

 

Thanks & Regards,

Prashant Sangle

https://predoole.com/

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
sunny_talwar

@PrashantSangle - it might need to be sorted first by Product and the StartDate desc

NoConcatenate
Temp1:
LOAD *,
     If(Previous(Product) <> Product, '-', Date(Previous(StartDate)-1)) as nextDate
Resident Temp
Order By Product, StartDate desc;
komminenianusha
Partner - Contributor III
Partner - Contributor III
Author

Thank you  very much @PrashantSangle  for your help. It is working as expected.