KNOWLEDGE BASE

How to calculate the number of days from each customer's 1st purchase date to the 2nd purchase date


Published: 14 Sep 2022
Last Modified Date: 15 Sep 2022

Question

How to calculate the number of days from each customer's 1st purchase date to the 2nd purchase date.

Environment

  • Tableau Desktop

Answer

1. Connect to Sample -Superstore.
2. Create a new calculated field as following.
     Name : 1st Purchase Date
     Calculation :  { FIXED [Customer Name]:MIN ([Order Date])}
3. Create a new calculated field as following.
     Name : 2nd Purchase Date
     Calculation : { FIXED [Customer Name]:
                          MIN(IF [Order Date] > { FIXED [Customer Name] :
                          MIN([Order Date])} THEN [Order Date] END)}
4. Create a new calculated field as following.
     Name : Difference 1st - 2nd Purchase Date
     Calculation : DATEDIFF('day',[1st Purchase Date],[2nd Purchase Date])
5. Drag [Customer Name] to Rows.
6. Drag [Difference 1st - 2nd Purchase Date] to Text in Marks.
User-added image
Did this article resolve the issue?