Question.
I have a database with two tables:
Table 1 - Invoice Table
- Transaction ID (Auto Number)
- Invoice Number
- Invoice Date
- Invoice Amount
Table 2 - Invoice Payment Table
- Invoice Payment Reference ID (Auto Number)
- Transaction ID (linked to Table 1)
- Payment Amount
- Payment Date
I want to be able to pull a customer balance as at a particular date by placing a date filter in the query. Say for instance Transaction ID 1 has an invoice #3 invoice date March 3 2011 and invoice amount $400.00. The customer made a payment of $20 on March 3, $50 on March 4 and $60 on April 1. I want to be able to pull the customer balance as at any date and it reads the correct thing...so say I pull the customer balance as at March 31 the customer balance should be $270.
What I have done thus far, was to create a cross tab query. I am able to pull the balances as at a particular date as I created a field in the master query named "date criteria" which is used as the filter as it is a combination of the payment date and invoice date...based on the later date. However, in the crosstab query the invoice amount is duplicated each time a payment is made.
Is there a way to create a running balance on a transaction id so that i could pull the balance for a customer at any given point in time?
5 3893 - Given the Data that you supplied, the actual Balance should be $330 and not $270, namely:
- $400 - ($20 on 3/3 + $50 on 3/4) = $330
-
'The payment of $60 on April 1, is after the posted date of 3/31/2011.
- This being said, I have arrived at an awkward solution, but nonetheless a solution so far.
- I'll post the SQL, Function Declaration, as well as the Demo that I used for this Thread.
- View this as only a Temporary Solution until a better one is forthcoming.
- SELECT [Invoice Table].[Transaction ID], [Invoice Table].[Invoice Amount], [Enter Date] AS [Date],
-
fCalcBalance([Invoice Table].[Transaction ID],[Invoice Amount],[Enter Date]) AS Balance
-
FROM [Invoice Table] INNER JOIN [Invoice Payment Table]
-
ON [Invoice Table].[Transaction ID]=[Invoice Payment Table].[Transaction ID]
-
GROUP BY [Invoice Table].[Transaction ID], [Invoice Table].[Invoice Amount], [Enter Date],
-
fCalcBalance([Invoice Table].[Transaction ID],[Invoice Amount],[Enter Date]);
- Public Function fCalcBalance(lngTransID As Long, curInvoiceAmt As Currency, dteDate As Date) As Currency
-
fCalcBalance = curInvoiceAmt - DSum("[Payment Amount]", "[Invoice Payment Table]", "[Payment Date] < #" & _
-
dteDate & "# AND [Transaction ID] = " & lngTransID)
-
End Function
Something like this - SELECT InvoiceNumber,
-
(InvoiceAmount -
-
(SELECT SUM(Payments) FROM PaymentsTable
-
WHERE PaymentDate <= #3/31/2011# AND InvoiceNumber = T.InvoiceNumber)
-
) AS Balace
-
FROM TableInvoices AS T
Thanks a million!!!!!! I am going to try it out now
@Rabbit - Is there any way in which you can Parameterize the Date inside the Sub-Query, instead of Hard-Coding it?
Yeah, you can do it the same way you would for a regular query. I'm just responding from a phone so it's easier to type shorter messages without scrolling back and forth to look at the original message.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Ovidiu |
last post by:
How can I get all files in a project that were checked in until a certain
date/time ?
|
by: Martien van Wanrooij |
last post by:
I would like to retrieve, let us say, the First Monday after a certain date,
so my (imaginary) function
could be something like
echo weekdayAfter("28 July 2005", "Monday") should return "1 August...
|
by: Joecx |
last post by:
Does anyone know how to give a date (not today's date) and have the program
calculate the previous monday's date from it? Any help would be appreciated.
Thanks!!!!
Joe
|
by: TJS |
last post by:
what namespaces are required so I can do a simple calculate age from date of
birth ?
|
by: dermot |
last post by:
hi,
I'm opening a file dialog in a vb.net form.
I want to show only files modified after a certain date.
Is there anyway to filter for this?
Thanks
|
by: rohayre |
last post by:
Im a long time java developer and actually have never done anything
with java scripting. I'd like to write a short simple script for
calculating a date in the future based on today's date and a...
|
by: simba |
last post by:
Hi,
I am doing an online booking project and was wondering if anyone has any ideas on how I can display rooms that are not booked on a certain date. The query that I have that displays all rooms...
|
by: neeZy |
last post by:
Hey Guys,
I have a make-table query in which I'm tryin to display a table that shows results past a certain date (12/31/2006). The date column is in proper Date/Time format - Short Date format to...
|
by: awojciehowski |
last post by:
I am working with a database now and need some guidance.
I am attempting to input an auto calculation. I have the ability to enter a date in a text box on a form. I want to be able to have...
|
by: didajosh |
last post by:
Fund-----------LockUpDate----------Liquidity
A-----------------12-31-2007-------------6
B-----------------02-29-2008-------------3
C-----------------05-31-2008-------------12
There are funds...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |