Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Mastering Change Data Capture: Read Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Categorize customers dependent on selected Date

Hi *,

I'm trying to categorize my customers into "known-customers" and "new-customers" dependent on the selected order date.
E.g.
The Customer 3 (Elvis P.) was created on 03.03.2009. He ordered 07.07.2008 and 01.04.2009.
If I select the year 2009 he has one order and is a known-customers because there was an order in 2008.
If I select the year 2008 he is a "new customer" because his first order was in 2008.
Is there a way to implement this?

Thanks.
Regards

Aloah

3 Replies
Not applicable
Author

Aloah,

Try this after you have loaded the Orders table in your example:

Load *,
if (previous(Customer_ID) = Customer_ID, 'Existing', 'New') as Customer_Type
resident Orders
order by Customer_ID, Order_Date;

This will create a new table and the original 'Orders' can be dropped.

Regards,

Gordon

Not applicable
Author

Thanks Gordon. Works perfect.

johnw
Champion III
Champion III

And as a side comment, I believe it is faster and uses less memory to just join the table back to itself rather than loading a new table and dropping the first, i.e.,

LEFT JOIN (Orders)
LOAD
Order_ID
,if(previous(Customer_ID)=Customer_ID,'Existing','New') as Customer_Type
RESIDENT Orders
ORDER BY Customer_ID, Order_Date
;


Also, you'll need to use max(Customer_Type) when there are multiple orders in the year, as only the first order will have a customer type of New.