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: 
harendra_singh
Partner - Contributor II
Partner - Contributor II

How to create 'From' and 'Till' dates from a single date field ?

Hello All,

I want to know how to create a snapshot i.e., From and till from a single date field. For example, An inventory has a product 'X' cost xyz upto this date and changes after this date.

 

ItemsPriceDate
Apple1005/01/2017
Banana2010/01/2017
Apple1520/01/2017
Guava3017/01//2017
Guava40

25/01/2017

I need this as a result:

 

ItemssPriceFromTill
Apple1005/01/201719/01/2017
Apple1520/01/2017
Banana2010/01/2017
Guava3017/01/201724/01/2017
Guava4025/01/2017

Any help would be helpful. Thanks anyway

1 Solution

Accepted Solutions
effinty2112
Master
Master

Hi Harendra,

Try:

Data:

LOAD * INLINE [

    Products, Price, Date

    Apple, 10, 05/01/2017

    Banana, 20, 10/01/2017

    Apple, 15, 20/01/2017

    Guava, 30, 17/01/2017

    Guava, 40, 25/01/2017

];

OrderedData:

LOAD

Products,

Price,

Date as From,

if(Products = Peek(Products) , Date(Peek(From)-1), Date(Today())) as To

Resident Data Order by Products, Date desc;

DROP Table Data;

Giving:

Products From To Price
Apple05/01/201719/01/201710
Apple20/01/201730/08/201715
Banana10/01/201730/08/201720
Guava17/01/201724/01/201730
Guava25/01/201730/08/201740

If you prefer you can get

Products From To Price
Apple05/01/201719/01/201710
Apple20/01/2017 15
Banana10/01/2017 20
Guava17/01/201724/01/201730
Guava25/01/2017 40

by changing the line of script that defines the field To:

if(Products = Peek(Products) , Date(Peek(From)-1)) as To

cheers

Andrew

View solution in original post

4 Replies
effinty2112
Master
Master

Hi Harendra,

Try:

Data:

LOAD * INLINE [

    Products, Price, Date

    Apple, 10, 05/01/2017

    Banana, 20, 10/01/2017

    Apple, 15, 20/01/2017

    Guava, 30, 17/01/2017

    Guava, 40, 25/01/2017

];

OrderedData:

LOAD

Products,

Price,

Date as From,

if(Products = Peek(Products) , Date(Peek(From)-1), Date(Today())) as To

Resident Data Order by Products, Date desc;

DROP Table Data;

Giving:

Products From To Price
Apple05/01/201719/01/201710
Apple20/01/201730/08/201715
Banana10/01/201730/08/201720
Guava17/01/201724/01/201730
Guava25/01/201730/08/201740

If you prefer you can get

Products From To Price
Apple05/01/201719/01/201710
Apple20/01/2017 15
Banana10/01/2017 20
Guava17/01/201724/01/201730
Guava25/01/2017 40

by changing the line of script that defines the field To:

if(Products = Peek(Products) , Date(Peek(From)-1)) as To

cheers

Andrew

harendra_singh
Partner - Contributor II
Partner - Contributor II
Author

Thanks Andrew

its_anandrjs
Champion III
Champion III

Create your table this ways and use PEEK and PREVIOUS, Order By

Source:
LOAD ProductsPrice, Date(Date#(Date,'DD/MM/YYYY')) as Date;
LOAD * Inline
[
Products,  Price,     Date
Apple,     10,  05/01/2017
Banana,    20,  10/01/2017
Apple,     15,  20/01/2017
Guava,     30,  17/01/2017
Guava,     40, 25/01/2017
]
;

NoConcatenate
Temp1:
LOAD
Products,
Price,
Date as From_Date,
if(Products = Peek(Products),Date(Previous(Date)-1),'') as To_Date
Resident Source
Order By Products,Date desc;
DROP Table Source;

NoConcatenate
Final:
LOAD * Resident Temp1 Order By Price;
DROP Table Temp1;

EXIT Script;

Img9.PNG

harendra_singh
Partner - Contributor II
Partner - Contributor II
Author

Thanks Anand its very helpful...