473,394 Members | 1,703 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,394 software developers and data experts.

Creating A Query Expression Help

I created a query that has 2 sum fields. 1st Field is the sum of orders, 2nd field is the sum of count, I need the 3rd column for my expression which I am not sure how to write. Ultimately, I want field 1 to divide by field 2, and multiply by 2 for my percentage expression in field 3. Obviously, I am learning access and this form has already been a tremendous help to me.
Feb 13 '08 #1
9 2178
As I understand it, you are currently have the following query created:

The first returned value in the query is a SUM of the field [Orders]
The second returned value in the query is a SUM of the field [Count]

So the results of the query would be:

[SumOfOrders]
[SumOfCount]

Now you want to add in a third field:

([SumOfOrders] / [SumOfCount]) * [SumOfCount]

Is that right? (The reason I ask is because the calculation you wanted for the third field of the query will always be equal to [SumOfOrders].)

Regardless, you should simply be able to add the expression you wish to calculate into the third field (using the field names created by the query) and set Total to Expression.

Hope that helps! ^_^
Feb 13 '08 #2
not sure what I am doing wrong but I keep getting does not include the specified expression.





As I understand it, you are currently have the following query created:

The first returned value in the query is a SUM of the field [Orders]
The second returned value in the query is a SUM of the field [Count]

So the results of the query would be:

[SumOfOrders]
[SumOfCount]

Now you want to add in a third field:

([SumOfOrders] / [SumOfCount]) * [SumOfCount]

Is that right? (The reason I ask is because the calculation you wanted for the third field of the query will always be equal to [SumOfOrders].)

Regardless, you should simply be able to add the expression you wish to calculate into the third field (using the field names created by the query) and set Total to Expression.

Hope that helps! ^_^
Feb 13 '08 #3
Scott Price
1,384 Expert 1GB
not sure what I am doing wrong but I keep getting does not include the specified expression.

Please post for us the SQL statement you are currently using. We're stabbing in the dark without knowing exactly what you attempting! Open your query in design view, right click on the window bar and choose SQL view, then copy and paste here. Once you've copied the data, select the statement in the reply window, and click the # button on the top of this reply window to enclose the SQL statement in CODE tags. As an added bonus, you can manually edit the first tag to look like this: [code=sql]

Thanks!

Regards,
Scott
Feb 13 '08 #4
jaxjagfan
254 Expert 100+
not sure what I am doing wrong but I keep getting does not include the specified expression.
Make sure on the 3rd one and on you specify those as "Expressions" vice "Group", "Sum", Etc. You can also put a formula
Sum(tblOrders.Orders)/Count(tblOrders.Orders) in the column.
Feb 13 '08 #5
here is another one I need help on, Ill just post the sql view. I need another field that will divide the 2 first fields, and multiply them by 2 thank you for your help
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Sum([HTR BY RANK BY TRACK].SumOfxWIN) AS [Sum Of SumOfxWIN], Sum([HTR BY RANK BY TRACK].CountOfnDIST) AS [Sum Of CountOfnDIST]
  2. FROM [HTR BY RANK BY TRACK];
Feb 13 '08 #6
From what I understand you have an existing query called [HTR BY RANK BY TRACK] that has two fields [SumOfxWIN] and [CountOfnDIST].

You want to sum these two fields again and then divide the sum of [SumOfxWIN] by the sum of [CountOfnDIST], correct?

If so, you could write expression for the third field as:
[UnnamedField] : ([Sum Of SumOfxWIN] / [Sum Of SumOfnDIST])

Or as:
[UnnamedField] : (SUM([SumOfxWIN] )/ SUM([SumOfnDIST]))

In Design View, you just need to make sure that the third field has Total set to 'Expression' instead of 'SUM' and then cut and paste in the expression from above.

If you are getting an error that the query 'does not include the specified expression' it is most likely because one of the new field names ([Sum Of SumOfxWIN] or [Sum Of SumOfnDIST]) was not entered correctly into the calculated field. I have also found that saving the query after it is created, then running it sometimes clears up those errors.

Hope that helps! ^_^
Feb 13 '08 #7
When I close the query and reopen it, it asks for a parameter value, ahh very frustrating but getting there, any suggestions. Here is the sql view

sql code:

Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Sum([HTR BY RANK BY TRACK].SumOfxWIN) AS [Sum Of SumOfxWIN], Sum([HTR BY RANK BY TRACK].CountOfnDIST) AS [Sum Of CountOfnDIST], [HTR BY RANK BY TRACK].Result AS Expr1
  2. FROM [HTR BY RANK BY TRACK]
  3. HAVING ((([HTR BY RANK BY TRACK].[Result])=(Sum([SumOfxWIN])/Sum([SumOfnDIST]))));
************************************************** *********************************
From what I understand you have an existing query called [HTR BY RANK BY TRACK] that has two fields [SumOfxWIN] and [CountOfnDIST].

You want to sum these two fields again and then divide the sum of [SumOfxWIN] by the sum of [CountOfnDIST], correct?

If so, you could write expression for the third field as:
[UnnamedField] : ([Sum Of SumOfxWIN] / [Sum Of SumOfnDIST])

Or as:
[UnnamedField] : (SUM([SumOfxWIN] )/ SUM([SumOfnDIST]))

In Design View, you just need to make sure that the third field has Total set to 'Expression' instead of 'SUM' and then cut and paste in the expression from above.

If you are getting an error that the query 'does not include the specified expression' it is most likely because one of the new field names ([Sum Of SumOfxWIN] or [Sum Of SumOfnDIST]) was not entered correctly into the calculated field. I have also found that saving the query after it is created, then running it sometimes clears up those errors.

Hope that helps! ^_^
Feb 13 '08 #8
Ah, I think I see the problem! ^_^

See line 3? In that line you are telling the query to look for matches between field [Result] and Sum([SumOfxWIN])/Sum([CountOfnDIST]). What you want to do is set [Result] to that value, not look for a match. Right?

What you need is this added to the SELECT line:

Sum([SumOfxWIN])/Sum([CountOfnDIST]) AS Result

So what you would end up with is:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Sum([HTR BY RANK BY TRACK].SumOfxWIN) AS [Sum Of SumOfxWIN], Sum([HTR BY RANK BY TRACK].CountOfnDIST) AS [Sum Of CountOfnDIST], Sum([SumOfxWIN])/Sum([CountOfnDIST]) AS Result
  2. FROM [HTR BY RANK BY TRACK];
Does that help? :)
Feb 13 '08 #9
Ohh Thank Heaven... I now have it working. You have been very helpful being that I am new to this. :) Thank You Again!!!!!

Ah, I think I see the problem! ^_^

See line 3? In that line you are telling the query to look for matches between field [Result] and Sum([SumOfxWIN])/Sum([CountOfnDIST]). What you want to do is set [Result] to that value, not look for a match. Right?

What you need is this added to the SELECT line:

Sum([SumOfxWIN])/Sum([CountOfnDIST]) AS Result

So what you would end up with is:
Expand|Select|Wrap|Line Numbers
  1. SELECT DISTINCTROW Sum([HTR BY RANK BY TRACK].SumOfxWIN) AS [Sum Of SumOfxWIN], Sum([HTR BY RANK BY TRACK].CountOfnDIST) AS [Sum Of CountOfnDIST], Sum([SumOfxWIN])/Sum([CountOfnDIST]) AS Result
  2. FROM [HTR BY RANK BY TRACK];
Does that help? :)
Feb 13 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

29
by: shank | last post by:
1) I'm getting this error: Syntax error (missing operator) in query expression on the below statement. Can I get some advice. 2) I searched ASPFAQ and came up blank. Where can find the "rules"...
11
by: randi_clausen | last post by:
Using SQL against a DB2 table the 'with' key word is used to dynamically create a temporary table with an SQL statement that is retained for the duration of that SQL statement. What is the...
6
by: John Baker | last post by:
Hi: As those who have looked at this newsgroup recently will realize, I am a neophyte with Access, although I have experienced with Approach (the Lotus product). There are things I could easily...
8
by: Nanda | last post by:
hi, I am trying to generate parameters for the updatecommand at runtime. this.oleDbDeleteCommand1.CommandText=cmdtext; this.oleDbDeleteCommand1.Connection =this.oleDbConnection1;...
10
by: aaronrm | last post by:
I have a real simple cross-tab query that I am trying to sum on as the action but I am getting the "data type mismatch criteria expression" error. About three queries up the food chain from this...
11
by: funky | last post by:
hello, I've got a big problem ad i'm not able to resolve it. We have a server running oracle 10g version 10.1.0. We usually use access as front end and connect database tables for data extraction....
3
LMHelper
by: LMHelper | last post by:
How do I create a table from a query that will UPDATE each time I update the original table? I created a table from a query and it stayed the same for the past couple of months and did not...
2
by: Andy | last post by:
Hi guys I having a problem creating a report in Access 2003 project talking to a SQL database through and ODBC connect. After hours of trying things from Access Help, MSDN and Google I still...
11
by: Andrus | last post by:
I created dynamic extension methods for <= and < SQL comparison operators: public static IQueryable<TLessThanOrEqual<T>(this IQueryable<Tsource, string property, object value); public static...
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...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
jinu1996
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...
0
tracyyun
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...

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.