If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Calculating transactions by time
Here's my problem, I have customer transaction data that shows deposits and
withdrawals for a month. My data includes the customer ID, type of trans, date of trans, time of trans and amount. I am trying to come up with a way to count the number of times a customer makes a deposit then immediately makes a withdrawal. Obviously this will occur on the same date and within a minute or less of the deposit. I can pull a query showing the two relevent transactions together in a table but how do I count the number of occurrences. Any help is appreciated. Thanks! |
#2
|
|||
|
|||
Calculating transactions by time
SELECT COUNT()
Look it up in Help. -- Dorian "Give someone a fish and they eat for a day; teach someone to fish and they eat for a lifetime". "sabunim" wrote: Here's my problem, I have customer transaction data that shows deposits and withdrawals for a month. My data includes the customer ID, type of trans, date of trans, time of trans and amount. I am trying to come up with a way to count the number of times a customer makes a deposit then immediately makes a withdrawal. Obviously this will occur on the same date and within a minute or less of the deposit. I can pull a query showing the two relevent transactions together in a table but how do I count the number of occurrences. Any help is appreciated. Thanks! |
#3
|
|||
|
|||
Calculating transactions by time
Have you checked to see if the Totals query can do the calculating you need?
Try the Count aggregation... Regards Jeff Boyce Microsoft Access MVP -- Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "sabunim" wrote in message ... Here's my problem, I have customer transaction data that shows deposits and withdrawals for a month. My data includes the customer ID, type of trans, date of trans, time of trans and amount. I am trying to come up with a way to count the number of times a customer makes a deposit then immediately makes a withdrawal. Obviously this will occur on the same date and within a minute or less of the deposit. I can pull a query showing the two relevent transactions together in a table but how do I count the number of occurrences. Any help is appreciated. Thanks! |
#4
|
|||
|
|||
Calculating transactions by time
You'll need to join two instances of the table (CurrentAccounts below) on
the account holder being the same (same AccountNumber), the transaction's not being the same transaction (different TransactionID), one being a deposit (Credit 0), the other a withdrawal (Debit 0) and the transaction times being close (5 minutes or less in the example below) SELECT A1.AccountNumber, COUNT(*) AS ImmediateWithdrawals FROM CurrentAccounts As A1, CurrentAccounts AS A2 WHERE A1.AccountNumber = A2.Accountnumber AND A1.Credit 0 AND A2.Debit 0 AND A1.TransactionID A2.TransactionID AND DATEDIFF("n",A1.TransactionDate+A1.TransactionTime , A2.TransactionDate+A2.TransactionTime) BETWEEN 0 AND 5 GROUP BY A1.AccountNumber; Bear in mind that if one deposit and two withdrawals are made within a 5 minute period this would count as two occurrences, not one. Ken Sheridan Stafford, England sabunim wrote: Here's my problem, I have customer transaction data that shows deposits and withdrawals for a month. My data includes the customer ID, type of trans, date of trans, time of trans and amount. I am trying to come up with a way to count the number of times a customer makes a deposit then immediately makes a withdrawal. Obviously this will occur on the same date and within a minute or less of the deposit. I can pull a query showing the two relevent transactions together in a table but how do I count the number of occurrences. Any help is appreciated. Thanks! -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...ccess/201004/1 |
#5
|
|||
|
|||
Calculating transactions by time
Excellent! I followed your thought process, tweaked it a bit and got it work
for me. Thank you! "KenSheridan via AccessMonster.com" wrote: You'll need to join two instances of the table (CurrentAccounts below) on the account holder being the same (same AccountNumber), the transaction's not being the same transaction (different TransactionID), one being a deposit (Credit 0), the other a withdrawal (Debit 0) and the transaction times being close (5 minutes or less in the example below) SELECT A1.AccountNumber, COUNT(*) AS ImmediateWithdrawals FROM CurrentAccounts As A1, CurrentAccounts AS A2 WHERE A1.AccountNumber = A2.Accountnumber AND A1.Credit 0 AND A2.Debit 0 AND A1.TransactionID A2.TransactionID AND DATEDIFF("n",A1.TransactionDate+A1.TransactionTime , A2.TransactionDate+A2.TransactionTime) BETWEEN 0 AND 5 GROUP BY A1.AccountNumber; Bear in mind that if one deposit and two withdrawals are made within a 5 minute period this would count as two occurrences, not one. Ken Sheridan Stafford, England sabunim wrote: Here's my problem, I have customer transaction data that shows deposits and withdrawals for a month. My data includes the customer ID, type of trans, date of trans, time of trans and amount. I am trying to come up with a way to count the number of times a customer makes a deposit then immediately makes a withdrawal. Obviously this will occur on the same date and within a minute or less of the deposit. I can pull a query showing the two relevent transactions together in a table but how do I count the number of occurrences. Any help is appreciated. Thanks! -- Message posted via AccessMonster.com http://www.accessmonster.com/Uwe/For...ccess/201004/1 . |
Thread Tools | |
Display Modes | |
|
|