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

**URL:** <https://community.exploratory.io/t/how-to-calculate-duration-between-order-dates-for-each-customer-with-lag-function/3853>\
**Category:** HowTo\
**Created:** [January 29, 2025, 3:46pm UTC](https://community.exploratory.io/t/how-to-calculate-duration-between-order-dates-for-each-customer-with-lag-function/3853 "2025-01-29T15:46:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hide\_Kojima1](https://community.exploratory.io/user_avatar/community.exploratory.io/hide_kojima1/32/398_2.png) [@Hide\_Kojima1](https://community.exploratory.io/u/Hide_Kojima1)\
**Post date:** [January 29, 2025, 3:46pm UTC](https://community.exploratory.io/t/how-to-calculate-duration-between-order-dates-for-each-customer-with-lag-function/3853/1 "2025-01-29T15:46:22Z")

</div>

### 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”.

 ![image](https://community.exploratory.io/uploads/default/original/2X/9/99faa5e65ae9a0cde02b430913dd079dfe15a870.png)

### 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.

 ![image](https://community.exploratory.io/uploads/default/original/2X/3/36686e4faafa6012e2f2c4a20a585e6e923cb986.png)
