Gouping By And Suming Calculated Fields In A Query
Oct 23, 2007
I have been given the unenviable task of processing data from a 700,000 line database. As an seasoned Excel user but absolute Access beginner, I've managed to handle some of the simpler data requests but the latest request has me somewhat stumped. The problem is as follows:
The fields are:
[Loan]
[Valuation]
[Type]
I have created a query that calculates two fields based on this data:
i) [LTV] = [Loan]/[Valuation]. The code I have used for this is:
SELECT IIf([Valuation]=(0),Null,[Loan]/[Valuation]) AS [LTV]
ii) A percentile reference [P Range] calculated using the following code:
IIf([LTV]>0 And [LTV]<0.1,"P0",Null) & IIf([LTV]>0.1 And [LTV]<0.2,"P10",Null) & IIf([LTV]>0.2 And [LTV]<0.3,"P20",Null) & IIf([LTV]>0.3 And [LTV]<0.4,"P30",Null) & IIf([LTV]>0.4 And [LTV]<0.5,"P40",Null) & IIf([LTV]>0.5 And [LTV]<0.6,"P50",Null) & IIf([LTV]>0.6 And [LTV]<0.7,"P60",Null) & IIf([LTV]>0.7 And [LTV]<0.8,"P70",Null) & IIf([LTV]>0.8 And [LTV]<0.9,"P80",Null) & IIf([LTV]>0.9,"P90",Null) AS [P Range]
FROM [BASE TABLE]
I suspect this code is somewhat clumsy but it is the best I have managed so far!
My difficulty is creating an output in the query
First the outputs need to be grouped by [Type] and by [P Range]. Then I need the following other outputs
Count[P Range]
Sum[Loan]
Sum[LTV] in each subgroup
I tried adding a Group By to the query in the design view, but I get an error every time. How do I output this data?
I have tried to read up on this but haven't managed to create a successful query!
I've attached a simplified version of the database as an example and to show where I've got to with this query
Please help!
Thanks
Oli
View Replies
ADVERTISEMENT
Jan 7, 2008
Hi!
I have done a query which has calculated fields, but I can't edit the stored fields directly from the query, instead I have to go to the table so as to edit it. Is this the way it works or is something wrong?
SELECT [INSTRUCCIONES DE EMBARQUE].N_OP, [INSTRUCCIONES DE EMBARQUE].[N° FAC EXP], [INSTRUCCIONES DE EMBARQUE].[FECHA CUMP], [INSTRUCCIONES DE EMBARQUE].[DERECHO PGC], [INSTRUCCIONES DE EMBARQUE].[VTO DER EXP], [INSTRUCCIONES DE EMBARQUE].[IMPORTE REINTEGRO], [DETALLE CONTENEDOR].CANTIDAD, [DETALLE CONTENEDOR].[VALOR FOB], [INSTRUCCIONES DE EMBARQUE].[TIPO DE CAMBIO], [TIPO DE CAMBIO]*[VALOR FOB] AS [PRECIO VTA (ARS)], [PRECIO VTA (ARS)]*[CANTIDAD] AS [TOTAL(ARS)], [TOTAL(ARS)]/[TIPO DE CAMBIO] AS [TOTAL(USD)]
FROM [INSTRUCCIONES DE EMBARQUE], [DETALLE CONTENEDOR];
View 2 Replies
View Related
Sep 13, 2006
Hi,
I have read that it's not recommended to put calculated fields on a table and they should instead be calculated using a query.
How about if I need to store that calculated value in a table (e.g. field1 + field2 = value in field3)
How can I do that please?
Thanks,
B
View 5 Replies
View Related
Mar 26, 2008
I am trying to create a calculated field in a query, that shows money owed from customers. I have 4 different job codes that have their own prices. I also have customers with the amount of hours they owe for, for each job. There are two customers that owe for two different jobs. I know how to write in : Money Owed: [price per hour]*[number of hours]. but i want to have only one line for each customer when i run the query. How do i combine??
View 1 Replies
View Related
Aug 8, 2006
I have a detail form, which has controls populated from a query.
For example,
Name Number
xxxx xxxx
This can be any length depending upon the amount of database records, so there might be 5 names, or 4 names, etc.
I then need to sum these in the footer. Is the possible?
I just seem to get #Error displayed when doing SUM([ControlBoxName])
View 9 Replies
View Related
Sep 30, 2004
I have a calculated text box on a form:-
=[AnnualSavings]/[SKUAnnualSpendInPounds]*100
But, if both the Annual Savings and SKUAnnualSpendInPounds text boxes have a value of 0 the result of the calulation comes out as #Num!. I assume this is the error because I am doing 0 divided by 0.
Does anyone know if this is the reason for my error and if so is there anyway of changing the #Num! back into a 0 so that I can submit it to my tables.
Any help would be greatly appreciated
View 1 Replies
View Related
Apr 27, 2005
Here is my dilemma
I have a table called inventory that stores my different products and the quanitities i have in stock. I also have an orders table that handles a customer palcing an order for a certain product and the amount they want. What i want to happen is this: If a customer orders for example 5 widgets, I want my inventory table to automatically reflect the 5 widget deduction from the quantity in stock. Anyone know how to do this?
View 1 Replies
View Related
Mar 13, 2008
Im wondering how to make calculated feilds in a query?
Do i have to make the feild in a table the go to query?
View 1 Replies
View Related
May 18, 2005
I developed a query that calulates when a contract is reviewed i.e 5 weeks and 9 weeks after the commencement date. These are called CDE1 and CDE2. This works well and the CDE1 and CDE2 dates are displayed ok.
The query above is:
SELECT Contract.ContractNo, Contract.APSNo, Contract.Firstname, Contract.Surname, Contract.AgencyDesc, Contract.FacilityName, Contract.Designation, Contract.WeeklyHrs, Contract.PositionNo, Contract.ComDate, Contract.EndDate, IIf(DateAdd("ww",5,[comdate])<[enddate],DateAdd("ww",5,[comdate])) AS 1stCDE, IIf(DateAdd("ww",9,[comdate])<[enddate],DateAdd("ww",9,[comdate])) AS 2ndCDE
FROM Contract;
The problem is that I now want to access contracts under these CDE dates between two dates that is user defined (startdate) and (enddate).
As the above are calculated fields, how can I develop a new query based on the above as CDE1 and CDE2 are already calculated fields?
View 2 Replies
View Related
Aug 9, 2005
New to Access and learning the hard way. Im sure this is an easy one, but sure would appreciate the help. I am trying to sum a group of cells and display the total, which i have done. But I also want to store this total in my database. So my question is, how do i move my calculated total to my field that has the "record source" bound back to my field in the database? Hope that makes sense. Thanks in advance.
View 3 Replies
View Related
Sep 10, 2004
I have an Access 97 database with a form and a subform for invoice and invoice details. When I change the qty or price in the subform I have a calculated field on the main form that updates. I also have a button that when clicked brings up the payment screen with the totals from the previous screen. The problem lies when I change the qty or price and click the button right away, the next form pops up but does not take the new totals, it grabs the old ones. The calculated fields do not refresh fast enough. I have tried requery, refresh, and even a loop to make it wait before opening the payment form, but nothing seems to work. I'm at a loss. Any ideas would be appreciated
Thanks
Ken Reid
View 1 Replies
View Related
Sep 9, 2006
Now I can create a Query that adds, subtracts a specific column, but im having a hard time trying to get the information into a form since it don't seem to allow me to pick the query field which is calculated as a datasource. Can someone tell me how to make a calculated query column appear on a form as a field? Such if I type in monday in the regular table, the form will add a few days to the next available game? I have the information/code already in a query that displays the query right in a new table using the Expr method but I can't get the form to just simply display the field. Someone please help!
I see a few people asked close to the same question but nobody never answered so I am thinking it is impossible
View 3 Replies
View Related
Nov 30, 2006
I keep getting caught up in the same point over and over again. I need to save a calculated field's calculation to a table field. The problem is how do I do this? I already know about the rules but I need to do this and store that specific information. Can someone post a sample code? The problem is the code and codes I been using dont' seem to work any more. I was putting
fieldname = textbox2.txt
in the form before update box. The problem with that is it would give me an error if the data source the calculation pulls from is not in the table/form.
View 1 Replies
View Related
Apr 20, 2007
I know that it is bad form to store a calculated field in a table - normalization and all that - but I can see no other way around a need that I have.
I'm trying to make a database to store injury time for employees. If an employee is injured, he can do light work for a certain amount of time, but this light work need not be contiguous. But, the total time on light work must be known so as to see when it is used up.
For example:
Bob is injured on 4/1/06 and goes on light work on 4/2/06 until 4/5/06 (4 days). Bob is then taken off light work until 4/10/06 when he reinjures the same injury. This does not count as a new injury, because it is an aggravation of the old one. So, Bob goes back on light work on 4/10/06 until 4/15/06 (6 days).
So, I need to store Bob's total time on light work for this injury (10 days) so that I can keep a running total to check against the maximum for a single injury. All I can think of is to store the sum of days on light work as a field in Bob's injury record, but that means storing a calculated field in a table.
Am I missing an easy way to do this, or is there a method to do what I want that I am just not aware of?
Thanx for any help!
View 2 Replies
View Related
Aug 26, 2005
Hello All,
Probably trying to do the impossible.
Normally I would never (that’s a long time) have the results of a calculated field in a table, but I’m stumped.
Table1
TestID: Autonumber
Quantity: Number
Selected: Yes/No
Table2
SumID: Autonumber
TestID: Number, Foreign Key
Quantity Delivered: Number
Query1-Sum Query
Table2
TestID: Group
Quantity Delivered: Sum
Query2- Select Query
Record Sets
Query1 Table1
TestID-----------------------------------TestID
Quantity Deliverd Quantity
Select
Fields in Query2
TestID from Table1
Select from Table 1
Run Query
Can’t update “Select” field
So I’m thinking that I should create a 3rd query to update the summed Quantity Delivered into a new field in table 1. Which would in effect create a stored calculated field.
View 2 Replies
View Related
Dec 16, 2006
I need some help. My brain just can't grasp how to do this.
I have an Access DB. I sell vinyl records. I have an order form. When a customer orders a record, each vinyl record has a unique ID#. No two vinyl records are alike. I have four tables: Customers, Orders, Inventory, & Order Details. I have an "Order Form" form where I input all the info. It's an all-in-one form where you can view and data entry in one screen. The form has two subforms in it.
Here's the problem:
If a customer orders more than one item (i.e. a vinyl record), each Inventory_ID (representing one vinyl record) is associated with one Order_ID which is, in turn, related to one Customer_ID. If I have one Order_ID that has multiple Inventory_IDs (i.e. has ordered two or more vinyl records) that belongs to one customer, how can I calculate that total cost?
Currently, I have a calculated field within my all-in-one form that calculates only the price of the Inventory_ID that one currently sees on the subform. The Inventory_ID item has a set price, for instance $5.00. If I scroll through the ordered Inventory_IDs, the calculated field will only display the price of the product that you currently see. It's not really calculating anything, I guess. It's just bound to that field, but I need to sum up all the price fields for all the Inventory_IDs that are associated with one Order_ID & Customer_ID whether it's a query or calculated field...I just need it done so that it'll display on this form.
Any help would be much appreciated. I can show you whatever you need to see. Thanks in advance.
David
View 10 Replies
View Related
May 4, 2005
Could someone tell me what Event I need to put this code in to calculate my fields when the form first opens?
I have this code on both the After Update and On Change events which is working fine, but, when I first open the form, those calculated fields are blank and I have to perform a change or update before the calculations will appear each time.
If Not IsNull(Me.fcstloc) Then
Me.prodvolume = DSum("[volume]", "qryMonthlyEngineVolumes", "[product] = '" & Forms!Projects!product & "'" & " And [MonthID] Between " & Forms!Projects.MonthID.Column(0) & " And 12")
ElseIf Not IsNull(Me.prodvolume) Then
Me.prodvolume = DLookup("[2004volume]", "tblProjectDetails", "[projectid] = " & Forms!Projects!projectid & "")
End If
Thanks!
Toni
View 1 Replies
View Related
Jul 18, 2005
I have an Invoice Form with a Payments Subform. Here are the details:
frmInvoice
InvoiceID
Customer
ShipmentID
QtyShipped
UnitPrice
frmPaymentsSubform
PaymentID
InvoiceID
CheckNum
DateReceived
Amount
An invoice can be paid in multiple payments. (One-to-Many Relationship).
I have a calculated field that takes QtyShipped * UnitPrice, which gives me my total due. That works correctly. However, I want to have another calculated field that sums all of the payments (the Amount field). Then I want another field that takes the difference between the total due and the sum of all the payments, and gives me a Remaining Due calculated field.
Right now, my TotalPaid and TotalRemaining fields are marked with '#Error'. Is that because TotalPaid is a running sum? Every day I can go in and add a payment to an invoice, so the number would be constantly changing until it was paid in full.
Any suggestions would be great!
View 10 Replies
View Related
Sep 14, 2006
I have a small Database that produces invoices, Each invoice could have 5 items on it which are compeleted at different Dates. (cutting hair in an OAP Home) Invoice to be produced at the end of each month which shows what happened each week. This will be generated for each person in the home. I can display all the information in a form when inputing the invoice information. I want a button to copy the invoice number the client name and the total of the invoice to a new table. The total of the invoice is calculated control on the form.
How do I do this??? can anyone help
I need a total in a table to substract payments from.
All Help will be much appreciated.
View 1 Replies
View Related
Dec 19, 2006
I only seem to be able to add some 30 calculated fields to a form or report. Anything over this returns a #Name? error. I've seen this before but have searched this and other forums but cannot find an answer. I suspect a memory issue but I have 2 gb on Pc. Any Ideas?
View 10 Replies
View Related
Oct 18, 2004
I have created a report in Access that calculates the dates based on a date-type field in a query. I want to be able to use these calculated dates in another report and sort these dates in an ascending order. With the dates, I also want to display certain information from this report. Is it doable? Please let me know....ASAP if poosible...
Thanks!
View 6 Replies
View Related
Jan 6, 2005
Hi,
Is there a easy way of formating/rounding a number returned to a ListBox by a SQL_Query?
I have a List box in a Report that gets it's data from a SQL Query
via ListBox.RowRource = SQL_Statement
this SQL_Statement cointains two calculated fields that returns a number (float)
In the report I get the numbers as float - that is in exponential view (0.29143256234E10) etc
but this makes it difficoult to read.
I have tried multiple solutions and searched the net but still am stuck (exept doing it in a CPU
consuming way).
Is there a easy way of formating/rounding a number returned to a ListBox by a SQL_Query?
I want a result that have a maximum of 3 digits after "zero".
Thx
View 4 Replies
View Related
Apr 26, 2007
Hi all,
I need to figure out how to have two calculated fields written to the database table instead of just being displayed in the form.
The user selects a number from 1 to 5 in the first field, and a number from 1 to 7 in the second field. The first calculating field multiplies these two numbers and displays the result. The second calculating field determines where the resulting number fits in three ranges of numbers and displays the result as Low, Medium, Or High.
My problem is the calculated results are be displayed in the form but not being written to the table. I cannot create a report to display all the High results, etc.
How do I update the calculation field formula to write the results into the table so I can create queries/reports on the calculated data?
Thanks,
bugleboy62
View 3 Replies
View Related
Jun 19, 2014
This Works:I have a report with subreports that provide totals to the main report. The main report is grouped to provide the totals by customer. Here is the format:
Customer Labor Materials LineTotal
Cust1 $100 $10 $110
Cust2 $200 $20 $120
Cust3 $300 $30 $130
[Labor] - ControlSource =IIf([rptSchedE_STS_Sum_Installs].[Report].[HasData],[rptSchedE_STS_Sum_Installs].[Report]![TotalExtInstall],0)
This doesn't work:
I am trying to create totals for each field (i.e. LaborTotal = $600, see below)
Customer Labor Materials LineTotal
Cust1 $100 $10 $110
Cust2 $200 $20 $220
Cust3 $300 $30 $330
Totals $600 $60 $660
I've tried the following each resulting in #Error:
ControlSource =Sum(IIf([rptSchedE_STS_Sum_Installs].[Report].[HasData],[rptSchedE_STS_Sum_Installs].[Report]![TotalExtInstall],0))
ControlSource =IIf([rptSchedE_STS_Sum_Installs].[Report].[HasData],Sum([rptSchedE_STS_Sum_Installs].[Report]![TotalExtInstall]),0)
ControlSource =IIf([rptSchedE_STS_Sum_Installs].[Report].[HasData],Sum(Nz([rptSchedE_STS_Sum_Installs].[Report]![TotalExtInstall],0),0)
View 2 Replies
View Related
Jun 12, 2013
I have a production report with 4 one to many sub reports (material reworked, reclassified, rejected, and issued). Each of those sub reports has a sum field totaling up the material reworked, rejected, etc for that lot.
I need a calculated field that subtracts the totals in each sub report from the reported amount produced in the main report.
Should I do this with a calculated field on the report. If so how would I reference the summed fields in the sub reports?
Or should I put a summed field of the amount reworked, rejected, etc in the query the report is based on and make a calculated field off that.?
View 3 Replies
View Related
Sep 27, 2012
I have three columns where A is a number, B is a number and I want to make C = to the greater of the two. i.e.
Col A = 10, Col B = 12 therefore Column C = Col B or Col A = 12, Col B = 10 therefore Col C = Col A
View 4 Replies
View Related