I'm trying to figure out the time between each account's
orders. So, for example, the value in the
TimeElapsedFromLastOrder column for account #123 in the
second row above would be 6 days.
Thanks, that helps a lot!
You'll need to use the DMax() function to find the largest previous
order date for that account. This gets a bit snarky if there *was* no
previous order, but try something like this as a calculated field in
your query:
DateDiff("d", NZ(DMax("[OrderDateM]", "yourtablename", "[SAP#] = " &
[SAP#] & " AND [OrderDateM] < #" & [OrderDateM] & "#"), [OrderDateM]),
[OrderDateM])
Working from the inside out, the DMax() function will return the most
recent prior order date; if there is none, NZ will return the current
record's order date. DateDiff will then calculate the number of days
between the most recent prior order and the current record's order
date. There are some other ways you can treat the first order (i.e.
use #1/1/1900# in the NZ function to get a ridiculously large number
of days, or an IIF); the way I suggest will return 0 for the interval
if there is no prior order.