3 Replies Latest reply on Jul 1, 2016 5:54 AM by Josef Freedman

# How To Calculate days since previous Order

Hello,

I'm attempted to calculate days since previous order.

I have days since first order, and says since last order using:

Min Order Date: {Fixed email : MIN([order  date])}

Max Order Date: { Fixed email : MAX([order  date])}

I would like to find days since previous order for each order.

E.G.

order 1: 01/01/2015 Days since previous order = null (or zero)

order 2: 02/01/2015 Days since previous order = 1

order 3: 07/01/2015 Days since previous order = 5

I would like to do this using L.O.Ds., so that even if we have the order date filter to 07/02/2015 only, the above order 3, will still show 5 days since previous order.

I imagine I have to do something like

[order date] minus [previous order date]

where [previous order date] = maximum order date for that email address, that is less than order date of this order,

J

• ###### 1. Re: How To Calculate days since previous Order

Hi Josef,

Unfortunately, one cannot do everything recursive with LODs only, sorry.

The two main approaches are used, namely, a non-equi join or a window calculation.

Both ways are feasible when using Tableau.

While the former (via join) relays upon a DBMS of choice,

the latter could be done either in SQL (using window functions)

or in Tableau itself (using Table Calculations).

Please find the attached as an example of the latter.

Hope it could help.

Yours,

Yuri

• ###### 2. Re: How To Calculate days since previous Order

Please find the attached modified --

with a "self-join and filter" approach on Sheet 7a.

Yours,

Yuri

• ###### 3. Re: How To Calculate days since previous Order

Thanks Yuri,

This was actually how I had initially done it too. I have a few other conditions to build in, (such as days since previous *specific product* purchase, but this is a good foundation to start on, so thank you again.

J