Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Recursive Problem

I'm having problem with the recursion, as i need to find the following from the same table.

For my problem i'm taking product orders as sample data.

Problem : I need to find count of all the products which was ordered by same person within 72 hours of initial order.

Product Orders:

ProductId OrderDate OrderByUserId

1 12/12/10 3:45 1

2 12/12/10 4:45 2

1 12/13/10 3:45 1

2 12/12/10 4:45 33

2 12/16/10 4:45 12

2 12/12/10 4:45 2

Problem : I need to find count of all the products which was ordered by same person within 72 hours of initial order.

I'm not even sure if we can do this in Qlikview, Any help would be greatly appreciated.

1 Solution

Accepted Solutions
johnw
Champion III
Champion III

If by "initial order" you mean the first order for that customer, ever, regardless of any selections, perhaps handle it in script.

LEFT JOIN ([Product Orders])
LOAD
YourUniqueKeyField
,if(OrderTimestamp<=FirstOrderTimestamp+3,'Y','N') as OrderedWithin72Hours?
;
LOAD
YourUniqueKeyField
,OrderTimestamp
,if(OrderByUserId<>previous(OrderByUserId),OrderTimestamp,peek(FirstOrderTimestamp)) as FirstOrderTimestamp
RESIDENT [Product Orders]
ORDER BY OrderByUserId, OrderTimestamp
;

Then your chart is pretty simple:

Dimension = OrderByUserId
Expression = count({<OrderedWithin72Hours?={'Y'}>} distinct ProductId)

View solution in original post

3 Replies
johnw
Champion III
Champion III

If by "initial order" you mean the first order for that customer, ever, regardless of any selections, perhaps handle it in script.

LEFT JOIN ([Product Orders])
LOAD
YourUniqueKeyField
,if(OrderTimestamp<=FirstOrderTimestamp+3,'Y','N') as OrderedWithin72Hours?
;
LOAD
YourUniqueKeyField
,OrderTimestamp
,if(OrderByUserId<>previous(OrderByUserId),OrderTimestamp,peek(FirstOrderTimestamp)) as FirstOrderTimestamp
RESIDENT [Product Orders]
ORDER BY OrderByUserId, OrderTimestamp
;

Then your chart is pretty simple:

Dimension = OrderByUserId
Expression = count({<OrderedWithin72Hours?={'Y'}>} distinct ProductId)

Not applicable
Author

Thank You John,

Let me try this, i tried something similar but in a different way(SQL recursive query) but your solution seems better as what i did was extremely slow considering 2 mil+ rows .

Thanks for quick reply.

Not applicable
Author

Hi John,

Thank you for the solution, it worked fine, the only problem i had was that i had multiple dates to compare, it became really complicated load but it's working like a charm.

Thanks,

Nish.