3 Replies Latest reply on Mar 15, 2016 7:00 PM by Ekaterina Gordon

    Calculating the gap between purchase dates for each individual customer

    Ekaterina Gordon

      Hi everyone,


      I've looked through the forum topics related to the subject, but couldn't find quite what I need to calculate.

      Here is how the data-set looks like:


      UserID     OrderDate    

      123          01.01.2015

      234          02.01.2015

      345          04.01.2015

      234          03.01.2015

      234          06.01.2015

      123          08.01.2015


      I have a list of customers who are making purchases on different dates. Each purchase equals to a new record. Most of the customers purchase regularly hence their UserID is recorded as many times as they purchased. Only one record is made even if the same customer made several purchases on the same date.



      I need to calculate the gap (in days)  between two resent purchases individually for each UserID. The expected result should look like:

      UserID     OrderDate          Gap

      123          01.01.2015          0

      234          02.01.2015          0

      345          04.01.2015          0

      234          03.01.2015          1

      234          06.01.2015          3

      123          08.01.2015          7



      Any advice are greatly appreciated!