Calculate days between purchases

aalves

New Member
Joined
Sep 27, 2016
Messages
1
Hi,
I have a database which each entry is one purchase per one client. Now I want to understand how long each client takes between one purchase and another. Can anyone help me?

Example of the table:

Client ID / Date of purchase
Client 1 / 01/jan
Client 1 / 15/jan
Client 1 / 20/jan
Client 2 / 03/mar

In this example I wanted to know that Client 1 took 15 days from the first purchase and 5 days from the second to come back.

The idea is to make an histogram telling me how many clients take from 0-5 days, from 5-10 days, and so on.
Any ideas?

Thanks a lot!!
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
I figured there must be a way to do this with a subquery, but I confess I do struggle with those as they're often quite complicated for what I get into (for me, anyway).
If I put the sample data into a table called tblPurchDate and use the following, I get the first order date for a client versus the other order dates WHERE a client has placed more than one order. Thus client2 returns nothing. Perhaps it is a start. The result is below the sql statement.
Code:
SELECT tblDateSpan.ClientID, tblDateSpan.PurchDate, T.PurchDate
FROM tblDateSpan INNER JOIN tblDateSpan AS T ON tblDateSpan.ClientID = T.ClientID
WHERE (((T.PurchDate)>(SELECT Min([PurchDate]) FROM tblDateSpan AS PD WHERE tblDateSpan.PurchDate<(T.PurchDate))));

ClientIDtblDateSpan.PurchDateT.PurchDate
Client 11/1/20161/15/2016
Client 11/1/20161/20/2016
Client 11/15/20161/20/2016

<tbody>
</tbody>

This is about as far as I can take this. Maybe the initial results can feed a crosstab or totals query to refine it.
 
Last edited:
Upvote 0
yeah
I'm doing something similar for work

look at all patients and med orders over the last 6 months and find all patients who were prescribed 3 or more orders of a group of drugs within a 2 hour period

don't see anyway to do it except pull the entire recordset in and loop over it with vba
 
Upvote 0

Forum statistics

Threads
1,214,793
Messages
6,121,617
Members
449,039
Latest member
Mbone Mathonsi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top