Max Function In A Calculated Query
Dec 5, 2006
Hello,
I have a query problem and I have no idea how to solve it.
In the query there are 4 fields:
1) ID 2) PageRank 3) PageRankNormalized 4) PageRankValue
1) ID is the Primary Key
2) In the PageRank field there are values from 1 to 10
3) In the PageRankNormalized there is an expression PageRankNormalized: (3^[PageRank])
4) In the PageRankValue there is another expression PageRankValue: ((3^[PageRank])*100)/ Max ( [PageRankNormalized] )
Now when I run the query I get the following error message:
You tried to execute a query that does not include the specified expression 'ID' as part of an aggregate function. (Error 3122)
What I am trying to do is to calculate the PageRankValue (4) through an expression that divide ((3^[PageRank])*100) by the maximum value shown in the calculated field PageRankNormalized (3)
------------------SQL------------------------
SELECT [UNIVERSITIES by name].ID, [UNIVERSITIES by name].PageRank, (3^[PageRank]) AS PageRankNormalized, ((3^[PageRank])*100)/Max([PageRankNormalized]) AS PageRankValue
FROM [UNIVERSITIES by name];
---------------------------------------------
I am stucked and I am not sure how to use this Max function in a calculated query.
Thanks for your help !! :)
FF
View Replies
ADVERTISEMENT
Jan 30, 2014
I have a project at hand and it's been a predecessor of mine and client has asked me to do some work on it and extend functionality - but I have not really delved into Access before and I have had to worked my way through to this final snag :/
The Main Form has one sub form. This sub form allows the user to add multiple order items i.e. qty, stock, description from records within the system - fairly straight forward.At the last column of each row is the sub total of those particular items i.e.
Qty Unit | Item ID | Total
-----------------------
2 | 1234 | 80.00
------------------------
1 | 43526 | 20.00
------------------------
> | |
So the total is a function of =[Qty Unit] * [Unit Price].Then in the Footer of this SubForm is the Sub Total
=SUM([Qty Unit] * [Unit Price])
All fine and well..... However, the additional functionality kicks in.
Lets add the additional customer_id from the Main Form. Each Item bought is dependent on the customer_id i.e. they get special prices depending on who they are.So a New table is made which has the Item ID and SpecialPriceID (of a table to define as a specialPrice) and the Price linked to this Item and Special Price category. So say that there are two groups of users "wholesale" and "nonwholesale" these would be SP_1 and SP_2 and each client is defined either one of these, and each stock item has a Price for each SP_1 and SP_2. Hopefully I've explained myself there.
Back to the SubForm. So now the Total needs to calculated differently with needed the external customer_id from the Main Form.
Code:
Function CalculateSpecialPrice(ItemID As String, CustomerID As String, Unit As Integer)
Dim SPSelect As String
SPSelect = "SELECT Price FROM [Items_SpecialPrices] WHERE"
SPSelect = SPSelect & " ItemID = '" & ItemID
SPSelect = SPSelect & "' AND SpecialPriceID = (SELECT SpecialPriceID FROM Customers WHERE customer_id = " & CustomerID & ") "
[code]....
its the sub total I just keep on getting #Error on. I have even watched (using alerts) that the correct return variable is the same as the individual rows. This is the equation I used for the SubTotal within the footer.
=SUM(CalculateSpecialPrice([Item ID], [Form]![FormName]![CustomerID], [Qty Unit]))
#Error
View 2 Replies
View Related
Sep 15, 2013
I am struggling with the DateDiff fuction in a calculated field. After some study, I have used several variations of:
=(DateDiff("d",[DUED],Date())/7)
to calculate the time (in weeks) until a due date starting from today's date.
It continually turns up a specific date in the late 18 and early 1900's. It does not give me the number in weeks which was what I was hoping for.
Earlier I used a very simple: =DateDiff("m",[Birthdate],Date()) to calculate the age from a date of birth perfectly with no problems.
I do not understand why the formula is not working. Does it have to do with format or the fact that I am working with a future date and how can I rectify this problem?
View 4 Replies
View Related
Jan 22, 2013
Is there anyway to turn off the rounding function in calculated fields - I need to divide a currency amount by a whole number to calculate the number of full coin bags that will be needed (bags contain different totals according to the coin value) - a whole number.
Then the result is used to calculate how much loose coin will remain.
But regardless of the field type and/or the format, the number rounds when I reduce the decimal places to zero. I need the result to be the whole number and to calculate as the whole number.
View 4 Replies
View Related
Dec 11, 2013
So basically I need making a function that will count the number of records from another table/query based on a field from the current query.
View 2 Replies
View Related
Mar 6, 2007
Hi,
I am trying to display all records that are 30 days old from date of registration (& not paid). I have:
30 Days: [SrDate]+30
SrPaid = No
But I don't want to see those that have registered in the (say) last few days, but only those that have not paid and 30 days are up. How would I achieve this?
Thank you
View 2 Replies
View Related
Mar 6, 2007
Hi,
I am trying to display all records that are 30 days old from date of registration (& not paid). I have:
30 Days: [SrDate]+30
Paid = No
But I don't want to see those that have registered in the (say) last few days. How would I achieve this?
Thank you
View 3 Replies
View Related
Nov 23, 2007
I have an inventory transaction file that has quantity on hand as a calculated field. I am trying to add this unbound field to a report using a query but I can't figure out how to add my quantity on hand field to the query since it is a calculated field and not a bound control.
Any help would be appreciated.
Thanks
darrrellx
View 1 Replies
View Related
May 4, 2006
Please look at the attached sample db file and the text file explaining the problem.
Thanks
View 1 Replies
View Related
Jun 20, 2006
Hi everyone,
OK this is a pretty big question, but here it is....
I am not quite sure that a query is the best thing to use in this case, but I think it might be possible. Here is what I need to do: I have a table with information about oil well production. In this table the production of each oil well is recorded once a month (Barels of Oil, Water, and amount of Gas produced, and the number of days that the well produced in that month). This table ranges in dates from 1986 to 2006 and has records every month in that time span. You can see a sample of how the design of this table is in the attachment (Table: [Well Data]).
What I need to do is have a query look at this main table and create another table with some calculated fields. This new table will have only 1 record for each well. You can see a sample of the table that needs to be created in the attachment (Table: [New Table]). In this table, the first 8 columns are not calculated at all, they are just recorded from the main table. The next columns are calculated. As you can see in the attached preview, the query needs to find the first 180 days (6 months) that a well is producing and sum the oil, gas, and water in that time. It also has to do this for the first 365 days (12 months). Then it has to record the earliest date that a well has in the [Well Start Date] column and the latest date a well has [Well End Date]. And last, it has to determine how many total days the well was producing (Subtract [Well End Date] - [Well Start Date]).
I know this is a lot to comprehend, so please ask questions if you don't understand me. I really appreciate your help!!
Thanks,
Chris
View 1 Replies
View Related
Nov 15, 2007
I can't seem to find a problem like this already answered....
I have these two calculated fields:
dtmNPacketDue: IIf([strRevTypeNIRB]="Full" Or [strRevTypeNIRB]="Termination(Full)",[dtmNIRBMtgDate]-28,[dtmNExpDate]-28)
dtmCOIDueDate: IIf([strRevTypeNIRB]="Termination(Full)" Or [strRevTypeNIRB]="Termination(Expedited)","N/A",[dtmNPacketDue]-42)
When I use the one in RED in a calculated field in a new query, things are peachy.
But when I use the one in BLUE in a calculated field in a new query, the message is #Error
My Calculated field (which produces an #Error) in the new Query is:
2ndCOINotification: [dtmCOIDueDate]-14
(if I insert [dtmNPacketDue] instead...it works
Perhaps my problem is that dtmNPacketDue (a calculated variable) is part of the BLUE calculated variable....??
Any ideas greatly appreciated....
View 4 Replies
View Related
Apr 24, 2006
Hola folks.
I am trying to create a calculated field in a query that subtract 2 fields within the same query.
That is, i have a FiscalWeekStart and FiscalWeekEnd pulling from a table. I created a CountofWeek field that count the weeks between the FiscalWeekStart and End using "DateDiff("w",[FiscalWeekStart],[FiscalWeekEnd])".
I also have a HolidayWeek field that pulls from a table using a
Count expression in the query.
My goal is to subtract the CountofWeek and the Holiday week calling it NonHolidayWeek using "NonHoliday Week: IIf(IsNull([CountofHolidayWeek]),[CountofWeek],[CountofWeek]-[CountofHoldayWeek])"
BUT IT IS ASKING FOR PARMETERS ON THE "CountofHolidayWeek".
Thanks for the help in advance.
TukTuk
View 1 Replies
View Related
Jul 21, 2006
I have a query that draws from two tables, and the field in question looks like this:
X: [TableData]![FieldA]*[TableNumbers]![A]+[TableData]![FieldB]*[TableNumbers]![B]
It all works fine and dandy, but once I set it to sort by this field and run the query, it gives me the parameter prompt, asking me to enter the Parameter Value of FieldA and then for FieldB.
Is there a work-around for this within the query?
The only other solution I have in mind is making another table from this query, and then creating another query just for sorting said table, but that seems inefficient at best.
View 2 Replies
View Related
Nov 8, 2006
I have the following calculated field in a query:
LoanNo:IIf([Stats].[LoanCnt]>1,[Stats].[LoanCnt] & " Loans",[Loan].[LnNo])
Within its query, it correctly displays the loan number associated with a particular loan.
However, when I run a second query
SELECT LoanNo
FROM qryLoanInfo
it comes up blank for every record (other fields are OK)
Does anyone have any idea what might be happening?
View 2 Replies
View Related
Dec 8, 2006
Hi,
I have a calculated field in my query called "outstanding".
this is how the query looks:
Expr: SubFormTotal
[qty]*[price]
Discount
...[Discount]
Expr:Total
.[SubFormTotal]-[Discount]
Deposit
.[Deposit]
BalanceToDate
.
[B]Expr: Outstanding
..[Total]-[Deposit]-[BalanceToDate]
PROBLEM: i want to search for all the "amount outstanding" that >0 HOWEVER when i put that as the criteria it asks me to enter values for other calculated fields
what am i doing wrong and how can i solve it?
thanks
View 7 Replies
View Related
Apr 17, 2007
I hope someone can help as I am stumped at present. I have created a calculated query using dateadd. I have a table that has date fields, ServiceContractAgreed and ServiceFrequency. The service frequency field holds a value of 3,6,9 or 12 in months. Using dateadd I can add the months to the ServiceContractAgreed field in a field called NextService, ie =IIf(IsNull([ServiceContractAgreed]),"N/A",DateAdd("m",[ServiceFrequency],[ServiceContractAgreed]))
This works fine but what I want to do now is create a parameter query to search the NextService field, using the between operator to search between dates. I've created a new query to do this but get every record back, no matter what dates I put in. It's probably something really simple to do but I'd be really grateful for any advice!
Cheers
Dave
View 2 Replies
View Related
Aug 1, 2007
Good afternoon,
I have a field that contains semester info ie: F07 Sep.
What I am trying to do is using an if statement to test for which month and returning a section number based on the month. I can make it work using an exact match but am trying to make it work on the partial match "Sep" so I don't have to change it next year as F07 stands for Fall 2007
This is what I've tried and various combinations.
Section1: IIf([tblOnlineCoursesDetails]![Semester]="* Sep","70","")
Having trouble getting this to work.
Any help or suggestions would be appreciated.
Thx
Jerry
View 1 Replies
View Related
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
Apr 1, 2008
I have a calculated date field in a query...if I try and sort by this field I get a data type mismatch.
[CONTREFF] is a date field in a table, [TERM] is a number field in a table. I am trying to calculate the year the contract expires in the "EndTerm" field. The calculation works fine, but I can't sort it.
EndTerm: DateSerial(Year([CONTREFF])+[TERM],Month([CONTREFF]),Day([CONTREFF]))
Please Help!!! Thank you ...
View 3 Replies
View Related
Mar 23, 2015
This is not the normal calculated fields in query's. What I want is different, I want it to be like
IFF(ShowID="A",[TotalSales],0)
Thing I have is, I want to know all the Total sales in on row that has Show A in it and then Total sales for Show B. Problem is, I have over 130 shows. How would do that?
View 6 Replies
View Related
Jun 4, 2014
I've been struggling with this for a while, and even though I understand the theory, I can't get my code to work correctly.
I have 2 fields:
CallbackFrequency & Last Contacted.
I want to use these fields to populate a third field (callBackOn) so that we can have a list of candidates that need to be called from a certain date.
CallbackFrequency is added from a combobox, so all values are either 1 Month, 3 Months, 6 Months, or 12 Months.
I have tried creating a calculated field directly in the candidates table, but apparently this is not possible.I've therefore tried to create a query using IIF statement that will calculate this value.To get to grips with the code, I'm only dealing with 1 callbackFrequency at the moment. So far I have:
CallbackOn: IIf([Candidates].[CallbackFrequency]="1 Month", [LastContacted],)
I have not factored in the date manipulation yet, as the query does not display the LastContacted date of the record it finds, it only shows a blank cell,
View 8 Replies
View Related
Nov 25, 2013
I Have some calculated fields in a query and want to update it in the table .So,is there anyway to store these fields.Otherwise can i store this Query data every month in database so that when i re-run the query the previous month data will not be affected.
View 1 Replies
View Related
Oct 5, 2007
Here's the situation.
I have a calculated value in an unbound textbox (avghcppmw). I want to run a query (qinsphistory) in which one of the fields is the value of the textbox (avghcppmw).
Is there any way to pull the value from the form and display it in the query. I'm assuming not.
I also assume the only way to do this would be to create a query that would calculate the textbox value and base (qinsphistory) on the newly made query.
Is this correct?
View 6 Replies
View Related
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 4 Replies
View Related
Sep 10, 2014
I am having a problem with calculating a date field in a query. Prior to this posting I've done some research and made several changes to my query. This only resulted in fixing one problem but then creating another problem. Original problem was I had 2 fields, arrived (23:36) and stemi (0:07). I use the following calculation AT_ST: DateDiff("n",[arrived],[stemi]) which resulted in -1409. So my research showed me I had a problem with the date whenever the time went past midnight and trying to calculate a zero hour number. I changed my calculation to
AT_ST: IIf([stemi]>=#11:59:00 PM#,(DateDiff("n",[arrived],[stemi])),(DateDiff("n",[arrived],[stemi]+1440) Mod 1440))
This works fine and gives me the result of 31 minutes which is what I want, however the problems comes in when I change to this calculation any where there was a negative time now has a 1400+ plus value. Such as arrived (7:37) and 1st_eck (7:18) = 1426 where as before it would report -14 (yes, negatives are acceptable for my reporting because sometimes a call to the hospital is placed before the patient arrives so we want to report on the negative splits). I've tried using a nested IIF to calculate for stemi time being less than arrived time, this didn't work when I tried to use it on the calculated query field. I was wondering if I could write something to check the value of the calculated field if it is greater than 1440 and if yes - subtract 1440 from it. So in the example above 1426-1440 = -14. Is it possible to do this within the query or do I need to do it using VBA
View 14 Replies
View Related
Jul 11, 2013
Im trying to run the following calculated query:
Total Value on order: Sum([Purchase Price])
I want to sum the total of all the purchase prices together so I know the total value on order. I keep getting an error: "You tried to execute a query that does not include the specified expression Purchase Order' as part of an aggregate function
View 2 Replies
View Related