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: 
Not applicable

How to get previous date of purchase as a new column?

Is it possible to add 'Previous date of purchase' as a separate column? Please help us...

    

Data set
Customer IDDateSales
1000110/10/201515
1000110/11/201520
1000110/12/201534
1000210/10/201513
1000210/14/201522
1000210/15/201522
1000210/16/201513
Desired Output
Customer Previous Purchase DateCurrent DatePurchased in Current Date?Total Sales
1000110/12/201510/16/2015No69
1000210/15/201510/17/2015Yes70
5 Replies
robert_mika
Master III
Master III

Customer 1001 did not buy on 10/16/2015

There is not 10/17/2015

What is the logic behind Purchased in Current Date?

Does this help?

T1:

LOAD [Customer ID],

     Date,

     Sales

FROM

(ooxml, embedded labels, header is 1 lines, table is Sheet1);

T2:

load

  [Customer ID] as CastID,

  min(date(Date,'DD-MM-YYYY')) as PreviousDate,

  max(Date(Date,'DD-MM-YYYY')) as CurrentDate,

  sum(Sales) as [Ttotal Sales]

  resident T1

  group by [Customer ID];

  drop table T1;

Not applicable
Author

Sorry for missing information and confusion.

Here my current date is 10/16/2015. In fact current date is always 'Report Run date' (here my report run date is 10/16/2015)

  • Here customer 10001 is not purchased on 10/16/2015 (current Date). So that 4th column = No
  • Same time, 10001 customer's previous purchase is 10/12/2015. Here 10001 customer previous or last purchase is 10/12/2015 (or same) because he never had a current date purchase.
  • But customer 10002 has current date purchase (10/16/2015). So that 4th column = Yes.
  • Here customer 10002 previous purchase is 10/15/2015.

    

Desired Output
CustomerPrevious Purchase DateCurrent DatePurchased in Current Date?Total Sales
1000110/12/201510/16/2015No69
1000210/15/201510/16/2015Yes70
robert_mika
Master III
Master III

So Current Date=Today?

What about the 10/16/2015 for 1001?

tresesco
MVP
MVP

May be like this?

Untitled.png

Edit: Corrected according to your updated desired result.

jonas_rezende
Specialist
Specialist

Hi, Muralidhar Raguthu.

Try code below. I just  inputted 02/16/2016 for test with today date. After, adapt for your necessity.

In Script

tmp_Sales:

LOAD * Inline [

Customer, Date, Sales

10001, 10/10/2015, 15

10001, 10/11/2015, 20

10001, 10/12/2015, 34

10002, 10/10/2015, 13

10002, 10/14/2015, 22

10002, 10/15/2015, 22

10002, 02/16/2016, 13

];

NoConcatenate

Sales:

LOAD

Customer,

Date(Date) as Date,

Sales

Resident tmp_Sales

order by

Customer,

Date;


DROP Table tmp_Sales;

Sales_Transform:

LOAD

Customer,

Date(Max(Date,2))    as [Previous Purchase Date],

Date(Max(Date))  as [Current Date],

if(Max(Date) =Date(Today())

  ,Text('Yes')

  ,Text('No')

) as [Purchased in Current Date ?],

Sum(Sales) as TotalSales

resident Sales

group by

Customer;



In Design

Thread205664.png

Hope this helps!