How to calculate duration between order dates for each customer with ‘lag’ function

Prerequisites

Assume that each row represents one order and that there are columns for the customer ID and order date

Open Window Calculation Dialog

From the Column Menu, select the “Create Window Calculation”.

Create Window Calculation

Select the “Customer ID” column to the Group Column, assign the “Order Date” column to Value, select “Difference From” as the Calculation Type, “Previous Value (LAG)”, and appropriate Period Unit (e.g. Day).

Check the “Sort Data Before Calculation” checkbox and select the “Order Date” column as the Columns to Sort.