Skip to content
Advertisement

Counts of re-purchase same product by the same customer in certain days or within certain duration days

I need to have the counts of re-purchase same product by the same customer in tow scenarios: in certain days and within certain duration.

Here is the sample data:

Duration is the difference between the last EndDay and the next StartDay for same customer purchasing same product.

For example:

For customer A, the EndDay at the first time he purchased “Shoe” was ‘1/4/2019. And the StartDay at the second time he purchased the ‘shoe’ was ‘1/7/2019’. So the duration was within 30 days.

For customer B, the EndDay at the first time he purchased “Shoe” was ‘5/8/2018. And the StartDay at the second time he purchased the ‘shoe’ was ‘8/2/201’. So the duration was within 60 – 90 days.

Expected outcome for first scenario: enter image description here

Expected outcome for second scenario: s

Thank you very much for your help in advance!!

Advertisement

Answer

Scenario 1:

Customer StartDay EndDay Product Cost 0-30 days 0-60 days 0-90 days total
A 2019-01-01 2019-01-11 Cloth 10.00 0 1 1 1
A 2019-03-03 2019-03-17 Cloth 10.00 0 0 0 0
A 2022-07-05 2022-07-09 Hat 10.00 0 0 0 0
A 2019-01-01 2019-01-04 Shoe 10.00 2 3 3 3
A 2019-01-07 2019-01-08 Shoe 10.00 1 2 2 2
A 2019-02-01 2019-02-03 Shoe 10.00 1 1 1 1
A 2019-03-03 2019-03-07 Shoe 10.00 0 0 0 0
B 2021-02-04 2021-02-07 Hat 10.00 0 0 0 0
B 2018-05-08 2018-05-09 Shoe 10.00 0 0 1 1
B 2018-08-02 2018-08-09 Shoe 10.00 0 0 0 0
C 2021-11-09 2021-12-09 Cloth 10.00 0 0 0 0
C 2020-06-06 2020-06-06 Hat 10.00 0 1 1 1
C 2020-07-08 2020-07-12 Hat 10.00 0 0 0 0
C 2020-06-06 2020-06-08 Shoe 10.00 0 0 0 0
E 2020-07-02 2020-09-01 Hat 10.00 1 1 1 1
E 2020-09-03 2020-10-01 Hat 10.00 0 0 0 0
E 2020-07-02 2020-07-08 Shoe 10.00 0 0 0 0

Fiddle

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement