Skip to main content
Announcements
Introducing Qlik Answers: A plug-and-play, Generative AI powered RAG solution. READ ALL ABOUT IT!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Generate Enddate by next StartDate

Hi

I have a table where I have the StartDate for the each registration by each student-ID.

But I need to generate the Endate by using the next registrations startdate - 1 day. And for the latest registration the enddate should be set to Date(Today()) whenever the script is loaded.

Can anyone help me?

Attached a qvd file with sampledata. Rename/remowe the .xml from filename

1 Solution

Accepted Solutions
MarcoWedel

or using your sample data:

tabTmp:

LOAD Distinct

  INKSKBERNR,

  ID,

  StartDate

FROM [http://community.qlik.com/servlet/JiveServlet/download/593204-121240/Tmp.qvd.xml]

(qvd);

Left Join (tabTmp)

LOAD Distinct StartDate,

    ID,

    If(ID=Previous(ID), If(StartDate=Previous(StartDate),Peek(EndDate),Date(Previous(StartDate)-1)), Date(Today())) as EndDate

Resident tabTmp

Order By ID, StartDate desc;

QlikCommunity_Thread_130269_Pic2.JPG.jpg

Due to duplicate rows your sample data is not unambiguously, so you might have some different solution in mind.

hope this helps

regards

Marco

View solution in original post

3 Replies
MarcoWedel

Hi,

one example:

matching currency exchange rate

tabExchangeRates:

LOAD * Inline [

date start, exchange rate

01/01/2014, 1.513

02/01/2014, 1.456

03/01/2014, 1.417

03/15/2014, 1.348

04/01/2014, 1.389

04/10/2014, 1.391

04/20/2014, 1.498

05/01/2014, 1.568

06/01/2014, 1.591

06/25/2014, 1.643

07/01/2014, 1.719

08/01/2014, 1.737

];

Left Join (tabExchangeRates)

LOAD *,

    AutoNumberHash128([date start], [date end]) as %PeriodID;

LOAD [date start],

    Alt(Date(Peek([date start])-1), Date(Today())) as [date end]

Resident tabExchangeRates

Order By [date start] desc;

QlikCommunity_Thread_130269_Pic1.JPG.jpg

hope this helps

regards

Marco

MarcoWedel

or using your sample data:

tabTmp:

LOAD Distinct

  INKSKBERNR,

  ID,

  StartDate

FROM [http://community.qlik.com/servlet/JiveServlet/download/593204-121240/Tmp.qvd.xml]

(qvd);

Left Join (tabTmp)

LOAD Distinct StartDate,

    ID,

    If(ID=Previous(ID), If(StartDate=Previous(StartDate),Peek(EndDate),Date(Previous(StartDate)-1)), Date(Today())) as EndDate

Resident tabTmp

Order By ID, StartDate desc;

QlikCommunity_Thread_130269_Pic2.JPG.jpg

Due to duplicate rows your sample data is not unambiguously, so you might have some different solution in mind.

hope this helps

regards

Marco