473,396 Members | 1,892 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Calculation Help Needed

I have a querie that needs to use multiple calculations (...I think...)
Fields:
TransID
TransDate
TransDescipt
ClientID
HoursBilled
BillingRate
AmountBilled
AmountPaid

Amount Billed is a calculation of HoursBilled*BillingRate

I need to add a field for AccountBalance that will keep a running total
of AmountBilled-AmountPaid for each ClientID.

I'm pretty sure I need to use group by, but how do I do the running
totals?? Do I need to do a sum of all AmountBilled and AmountPaid and
go from there??

Please help... feeling lost and kinda stupid here... just can't think
after my surgery 3 weeks ago... grrrrr

Marina

Mar 15 '06 #1
3 1359
"Marina" <ma*********@earthlink.net> wrote in
news:11**********************@j52g2000cwj.googlegr oups.com:
I have a querie that needs to use multiple calculations (...I
think...)
Fields:
TransID
TransDate
TransDescipt
ClientID
HoursBilled
BillingRate
AmountBilled
AmountPaid

Amount Billed is a calculation of HoursBilled*BillingRate

I need to add a field for AccountBalance that will keep a
running total of AmountBilled-AmountPaid for each ClientID.

I'm pretty sure I need to use group by, but how do I do the
running totals?? Do I need to do a sum of all AmountBilled
and AmountPaid and go from there??

Please help... feeling lost and kinda stupid here... just
can't think after my surgery 3 weeks ago... grrrrr

Marina

You do not want to add the field to the table, you recalculate
running totals on the fly when you want them. You do this by
building a sub-query or by using the dsum() aggregate function.

The idea is to sum AmountBilled-AmountPaid where ClientID in the
sub-query is equal to the ClientID in your table, and
BillingDate in the query <= Billingdate in the table.

--
Bob Quintal

PA is y I've altered my email address.
Mar 16 '06 #2
I can do this as it's own query, but can't seem to make a sub query
work.....

Main Query is:

SELECT ClientTransactions.ClientID, [client info].[Client FirstName],
[client info].[Client LastName], [client info].[Client Address],
[client info].[Client City], [client info].[Client State], [client
info].[Client Zip], ClientTransactions.TransactionID,
ClientTransactions.TransactionDate,
ClientTransactions.TransactionDescription,
ClientTransactions.HoursBilled, ClientTransactions.BillingRate,
ClientTransactions!HoursBilled*ClientTransactions! BillingRate AS
AmountBilled, ClientTransactions.AmountPaid
FROM [client info]
INNER JOIN ClientTransactions ON [client info].[Client ID] =
ClientTransactions.ClientID;

Sub-Query should be something like:

SELECT DISTINCTROW [client info].[Client ID],
Sum(ClientTransactions.HoursBilled) AS [Sum Of HoursBilled],
Sum(ClientTransactions.BillingRate) AS [Sum Of BillingRate],
Sum(ClientTransactions.AmountPaid) AS [Sum Of AmountPaid], ([Sum Of
HoursBilled]*[Sum Of BillingRate])-[Sum Of AmountPaid] AS Balance
FROM [client info] I
NNER JOIN ClientTransactions ON [client info].[Client ID] =
ClientTransactions.ClientID
GROUP BY [client info].[Client ID];

Mar 17 '06 #3
"Marina" <ma*********@earthlink.net> wrote in
news:11**********************@v46g2000cwv.googlegr oups.com:
I can do this as it's own query, but can't seem to make a sub
query work.....

Main Query is:

SELECT ClientTransactions.ClientID, [client info].[Client
FirstName], [client info].[Client LastName], [client
info].[Client Address], [client info].[Client City], [client
info].[Client State], [client info].[Client Zip],
ClientTransactions.TransactionID,
ClientTransactions.TransactionDate,
ClientTransactions.TransactionDescription,
ClientTransactions.HoursBilled,
ClientTransactions.BillingRate,
ClientTransactions!HoursBilled*ClientTransactions! BillingRate
AS AmountBilled, ClientTransactions.AmountPaid
FROM [client info]
INNER JOIN ClientTransactions ON [client info].[Client ID] =
ClientTransactions.ClientID;

Sub-Query should be something like:

SELECT DISTINCTROW [client info].[Client ID],
Sum(ClientTransactions.HoursBilled) AS [Sum Of HoursBilled],
Sum(ClientTransactions.BillingRate) AS [Sum Of BillingRate],
Sum(ClientTransactions.AmountPaid) AS [Sum Of AmountPaid],
([Sum Of HoursBilled]*[Sum Of BillingRate])-[Sum Of
AmountPaid] AS Balance FROM [client info] I
NNER JOIN ClientTransactions ON [client info].[Client ID] =
ClientTransactions.ClientID
GROUP BY [client info].[Client ID];
you said in a previous post: I need to add a field for AccountBalance that will keep a
running total of AmountBilled-AmountPaid for each ClientID.


that would be:
(SELECT sum([HoursBilled]*BillingRate]-[AmountPaid]) from
[clientTransactions] alias sqry WHERE sqry.clientID=[client
info].[clientID] and sqry.TransactionDate <= TransactionDate) as
Balance,

you'd put that as a single field in your main query. To get your
multiple columns, you will need to create multiple subqueries
each returning a single field.

--
Bob Quintal

PA is y I've altered my email address.
Mar 18 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: sandip | last post by:
Hi, Can anyone tell me how to calculate the ctual disk space needed for a table? The record length and number of records are known. A rough estimate of the disk space would suffice. Please...
2
by: Terry | last post by:
I have used the code provided in the PreciseDateDiff function at the following Access Web link to calculate the time change date (from Daylight to Standard time and vice versa): ...
9
by: chris vettese | last post by:
On my subform I have a field in the footer that totals the value of a field. On the main form I have referenced this field. I'm using this field in a calculation on my main form. The problem...
4
by: Michiel Alsters | last post by:
Hello everybody, I hope anybody can help me. I'll try to give a brief overview of my problem. I have running a program that performs a heavy calculation. To give the user feedback what the...
9
by: Klaus Bonadt | last post by:
I have found strange behaviour in casting floating point values in C++ 6.0 to int: If I enter in the watch window while debugging in version 6.0 the following term: (1.4 - 1.0) * 10.0 the...
10
by: roygon | last post by:
Hello, I have a C# application that runs a relatively complex simulation which, on a typical computer, could take up to 10 seconds. I am now trying to port this application over to ASP.NET so...
10
by: 60325 | last post by:
This is the page where I collect the data in drop-down boxes with values of 1-10 and send it to a submitted page to do calculations. Example: Employee1 TeamScore(1-10) Employee2 ...
5
by: The alMIGHTY N | last post by:
Hi all, Let's say I have a simple math formula: sum (x * y / 1000) / (sum z / 1000) I have to do this across 50 items, each with an x, y and z value, when the page first loads AND when a...
1
by: c8tz | last post by:
This is a query I have created that picks up the top 3 dates for this data (for example) : Tree Pos2 Date 1 15 23/08/2005 1 20 12/02/2006 1 32 15/10/2006 ...
1
by: csolomon | last post by:
I have an unbound text box which I use to get a calculation, called DM_SampleWt. This text box's control source is: =GetSize(,Nz(,0),.!,.!.(2)) I have written a function that will get the required...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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...
0
Oralloy
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.