Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling latest dated record from table

Status
Not open for further replies.

Prognewb

Technical User
Apr 20, 2006
76
US
Crystal XI on SQL 2008

I have a table that records customer transactions, and there are multiple transactions in the table per customer, so there could be 30 transactions listed in the table for one customer. There is a date field on each transaction (no more than one per day in the table), and a unique transaction number also. I need to pull just the record with the latest date for each customer. That date could be any time within the past year.
I have the report grouped by the customer number, with the transaction data in the details.
I tried a formula with maximum(date) insterted into the report, but it seemed to pull just the latest date and applied it to every line. I'm not sure how to apply it so it's relevant to the specific customer number and pull just the latest date for that group.
I searched around this site and other sites and didn't see anything quite as specific as what I'm looking for. Any help is appreciated.
 
Go to report->selection formula->GROUP and enter:

{table.transactiondate} = maximum({table.transactiondate},{table.customernumber})

This will return the most recent record per customer. If you then need to do any calculations across customers based on that record, you should use running totals, since non-group selected records would still contribute to the more usual summaries.

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top