Current date & record count

G

Guest

Using the below as an example, I need a query that would show (count) of 2
orders having 3 payments for the red shirt.

The query also needs to show that the most recent order was placed on
12/5/05 with a payment made on 3/2/06.

Example:

Item order date payment date
red shirt 1/3/05 1/5/05
12/5/05 1/8/06
3/2/06

If I need to perform two queries to do this it would be ok.

Thanks in advance for the help! Data is being imported from an Excel file.
 
T

Tom Ellison

Dear TT:

Is your accounting here open item. Are payments specifically allocated to
orders and their invoices. If so, then a payment may also have to be split
between 2 items.

If not, making an appearance that the payment on 1/5/05 was specifically for
the order on 1/3/05, and the payments on 1/8/06 and 3/2/06 were specifically
for the order on 12/5/05 is actually deceptive. This question also amounts
to asking whether each payment record is specifically related to a given
order (order date). To a large degree your table structure would tell me
this, but you have shown nothing of that. Do you actually split payments
between orders, assigning part of a payment to cover one order, and another
portion of that same payment to cover another order.

And, how do you treat two paymants made on the same date?

If you simply want to list order dates in one column and payment dates in
another, and if there is no association across the rows of your report
between orders and payments, then you could just Rank the orders by date and
the payments by date and join them on that. However, there are some tricks
to doing this:

- The ranking must be unique within each Item. A tie breaker needs to be
supplied beyond order date, which would not always be unique. There is
probably no reason why there could not be 2 or more orders on the same date
for the same Item. Break the tie with something like OrderNumber (my
suggestion). Same thing for uniqueness of payments. Break the tie with
something, perhaps the CheckNumber.

So if, two checks arrive the same day for the same Item, the one with the
lower check number would go first. There a slight risk of getting two
checks for the same Item on the same date with the same check number. They
could be on two different accounts! But this is sufficiently unlikely you
could probably get away with it. However, if you are logging the account
number on which the check is drawn, then adding this would make it almost
bullet proof for uniqueness. There's still the wild possibility of getting
two checks on the same date with the same account number, but on different
banks. I know, that's really wild. But thinking of the nearly impossible
is why I get the big bucks (yeah, right). So, if you have the bank routing
number, too, include that. I think it is now unique!

- Once you have a unique ranking on orders and another on payments within
each Item, you can JOIN on that ranking, as well as sorting the overall by
Item and Rank. However, you can never tell when the number of orders may be
more than the number of payments, or vice versa. There is likely to be some
of each. So the JOIN is what we call FULL OUTER. Access doesn't handle
this directly! You would need a UNION ALL of two JOINs, both LEFT and
RIGHT, of the queries that add the rankings.

I expect this general overview of the situation may not be enough to get you
through it. If you are an expert query coder, then perhaps this outline is
enough. If not, and you need some help with it, please post what is the
data you have for orders and payments, with table or query names, and
columns. You don't need to list all the columns, just the ones relevant to
what we have discussed, including the tie breaking columns such as I have
recommended. I can probably help you forward from there in 3 steps or so.

What do you think? I need to know first if you understand what I've said so
far. I prefer not to just do it for you, but to show you how it is done
step by step, and have you absorb it as we go.

Tom Ellison
 
G

Guest

Tom,

thanks very much for taking the time to respond to my posting. Here is
additonal information.

Table Structure: Item is text (255 characters). Dates are dates/time. For
the below example I left time out. A third field can be added which would be
a ship date. At this time duplicate orders and payment dates are not a
concern - the record count is! Join is based on Item. The Item and Order
Dates are one table. Payment is on another. Sort is Order Date and Payment
Date both in ascending order within Item.

Each order and payment date is for a specific Item (Order). The Only Order
and Payment Date that I am interested in as an output from the query are the
most recent ones.

The query output should show: Item 45567; Order Date 1/05/06; Payment Date
5/5/06; Number or Orders 4; Number of Payments 5 . It is recognized that
there can be a one to many relationship in both dates depending on a wide
range of variables - further anlaysis will be done after the amount of
Payments are subtracted by the number of Orders placed per Item.



Item order date payment date
45567 1/3/05 1/5/05
45567 12/5/05 1/8/06
45567 12/5/05 1/9/05
45567 3/2/06
45567 1/05/06 4/5/06
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top