Your query does not include the specified expression as part of an aggregate function

  • Your query does not include the specified expression as part of an aggregate function
  • Forum
  • Access Forums
  • Access
  • Aggregate Function Expression Error

  1. Aggregate Function Expression Error

    I am getting "YOUR QUERY DOES NOT INCLUDE THE SPECIFIED EXPRESSION 'CUSTOMER' AS PART OF AN AGGREGATE FUNCTION. After doing some research, I found I need to somehow group some or all of these columns but when I do so, I don't get the details listed for each customer. I also know the problem somehow lies with the formula. PLEASE HELP!

    SELECT Aging.[Customer], Aging.[Cust ID], Aging.[PO #], Aging.[Inv #], Aging.[Ship To/Store #], Aging.[Days Aging], Aging.[Inv Amt], Aging.[Bal Due], Email_Address.[Email Address], IIf(Max([days Aging]) Between 0 And 34,"",IIf(Max([days Aging]) Between 35 And 45,"Your a deadbeat",IIf(Max([Days Aging]) Between 46 And 60,"Loser","Pay Me"))) AS Expr1


    FROM Aging INNER JOIN Email_Address ON Aging.[Cust ID] = Email_Address.[Cust ID];


  2. Did you make this a Totals query (sigma character on ribbon)?

    You might find this easier to solve by using a query to populate a temp table with the calculations, minimum number of fields related to the calculation where at least one of them is related to the main table or query and is indexed. Then join that table to a 2nd query to get the remainder. A totals query sometimes cannot be grouped while still returning the desired records.

    BTW - by temp table I do not mean one that you continually recreate.

    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.


  3. I am not sure what you are trying to tell me (my Access skills are very basic). I tried doing the two things below (thinking maybe this was what you were telling me I should try):


  4. I just rebuilt the entire query and joined the table. It seems to be working now.

    Thank you.


  5. referring to character at far right of image

    Then there is always my friend Google who has 618,000 things to say when I asked him "ms access totals query".

    Your query does not include the specified expression as part of an aggregate function

    Clicking that may not be the entire solution for your problem but it is a prerequisite.
    You might want to post a zipped db copy if you get to struggling with this a lot. How to:

    https://www.accessforums.net/showthread.php?t=70301


Your query does not include the specified expression as part of an aggregate function

Similar Threads

  1. Replies: 3

    Last Post: 07-11-2018, 08:40 AM

  2. Replies: 1

    Last Post: 06-14-2015, 09:48 AM

  3. Replies: 5

    Last Post: 11-19-2012, 01:44 PM

  4. Replies: 2

    Last Post: 09-26-2011, 03:39 PM

  5. Replies: 1

    Last Post: 11-27-2010, 05:18 PM

Your query does not include the specified expression as part of an aggregate function
Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

  • BB code is On
  • Smilies are On
  • [IMG] code is On
  • [VIDEO] code is On
  • HTML code is Off

Forum Rules

  • #1

I have an expression on a query that is not calculating. It is for TotalFloorTaxDue.

The formula is a simple on where I tax the total of "TaxDuePacks20s"+"TaxDuePacks25s" to give me total floor tax due.

This is the expression that I have entered is TotalFloorTaxDue:Nz([tblCigaretteDataCollection]![TaxDuePacks20s],0)+Nz([tblCigaretteDataCollection]![TaxDuePacks25s],0)

When I try to put in a simple sum calculation entry of TotalFloorTaxDue: Sum([tblCigaretteDataCollection]![TaxDuePacks20s]+[tblCigaretteDataCollection]![TaxDuePacks25s]) I get an error message of "Your query does not include the specified expression 'SalesandUseTaxNumber' as part of an aggregate function." so I have discarded this expression.

There could be instances where someone may have zero in either the 20's or the 25's of the packs. Any suggestions as to why my top expression is not working?

  • #2

No idea. Syntax looks just fine. Except maybe don't need the table prefix.

The Sum() expression will, of course, only work in an aggregate query or in textbox on form/report in a header/footer section.

ypma

Registered User.

  • #3

Liz Johnson, my first thought without see your query, is that perhaps the totals field of the query does not have group by for "SalesandUseTaxNumber"otherr members might have further suggestions

Regards Ypma

plog

Banishment Pending

  • #4

"Your query does not include the specified expression 'SalesandUseTaxNumber' as part of an aggregate function.

My vote is with ypma. Here's a simple rule when using an aggregate function (MAX, SUM, COUNT, etc.):

When you use those functions every field in the SELECT has to be in the GROUP BY or must be included in an aggregate function (COUNT, MAX, SUM, etc).

My guess is you simply tried to add SUM to this one field without adding a GROUP BY clause. No dice. Click the Sigma/Summation symbol in the ribbon to make this an aggregate query.

Your query does not include the specified expression as part of an aggregate function

arnelgp

..forever waiting... waiting for jellybean!

  • #5

If the first query is ok.
Create another Total query based on the first query.

  • #6

This is great help. This may help me with another problem that I was coming up to. I do have locations by SalesandUseTaxNumber. I do need to get a total due for the SalesandUseTaxNumber also. I have a sub-form that I am trying to get a line total due. Then I was going to try to create an expression that would then give me a "grand" total for the SalesandUseTaxNumber. I'm not very well versed in macros and functions so any help on this would be appreciated.

Is it possible to get the Total for the line item on the sub form (which is the expression I have originally asked about) and then also get the grand total?

I've tried to look up more information about the aggregate function but not having much luck with that. I'm still at a loss on how to make the line total function work. Would it not be working because the 2 items I'm trying to add together are already an expression?

plog

Banishment Pending

  • #7

I have no idea what we are working on now--form, subform, query, function, expression.

You posted in the query section, so if that's what you want to work on post 2 sets of data:

A. Starting data from all relevant tables. Include table and field names and enough data to cover all cases.

B. Expected results of A. Show what data you hope your query will return when you feed it the data in A.

  • #8

Hi Plog,
So, in my query, I did put all the relevant information that I would need to come up with my expected results. I have my SalesandUseTaxNumber, LocationID, BusinessName, TobaccoLicenseNumber, Amended, Packof20s, TaxRateon20s, TaxDuePacks20s, Packof25s, TaxRateon25s, TaxDuePacks25s, TotalFloorTaxDue.

I have expressions for the TaxDuePacks20s and also TaxDuePacks25s. These two different expressions are calculating ok. The final expression I need is to add up these two TaxDue amounts. This is the expression I am using. It is not calculating the total. I don't know why?

TotalFloorTaxDue:Nz([tblCigaretteDataCollection]![TaxDuePacks20s],0)+Nz([tblCigaretteDataCollection]![TaxDuePacks25s],0)

There can be zero amounts in either Packsof20s or Packsof25s.

plog

Banishment Pending

  • #9

Define, not "calculating the total". Error message? Field prompt? Incorrect results? No results? Sample data.

  • #10

qry73A421
SalesandUseTaxNumber LocationID BusinessName TobaccoLicenseNumber Amended Packof20s TaxRateon20s TaxDuePacks20s Packof25s TaxRateon25s TaxDuePacks25s TotalFloorTaxDue
123456 7654321 Test 2 No 3 $0.50 $1.50 5 $0.63 $3.13 0

If you will notice, the last field just has a zero when this should have a total of
$4.63

Mark_

Longboard on the internet

  • #11

Which of your fields are expressions? ACCESS does not play nice when you try to use the result of one expression in another expression in the same query. You will normally want ONE query to generate your calculated values, then a SECOND that works off the first to generate your second order expressions.

Example:
Query 1
ProductCost
ProductTaxRate
ProdTax: (ProductCost * ProductTaxRate)

Data in
$100 10%

Result
$100 10% $10

Query 2
ProductCost
ProductTax
TotCost: (ProductCost + Product Tax)

Result from above
$100 $10 $110

Hope this helps!

  • #12

1 query should be able to do the 'second order' calcs. I have done it.

  • #13

Thank you for your help on this. So, instead of making a 2nd query and then tying that back to the 1st query, which seems tedious, I changed my Total expression. I just made this expression mimic what was in the other two expression and adding them together. Since the expressions were so simple (tax * rate) and then adding the two, this didn't take any time. I had to delete the field and then re-add it back. I had it so confused.

Thanks for the help. By your comments, I realized that I couldn't use the fields with the expression in my final expression and had to change that.

Thanks again for your help.

Mark_

Longboard on the internet

  • #14

You are very welcome,

Even though you did not need it this time, please remember that you CAN use one query as the source for another. You will eventually find a case where it helps out immensely, especially if you have several other queries that are going to be driven off of the same underlying data.

What does it mean when access says your query does not include the specified expression?

Every Column that is not an aggregate function (or WHERE or Expression) needs to be listed in the Group By List. that's why you are getting the error.

Why WHERE clause Cannot be used with the aggregate functions?

Aggregate functions are not allowed because the WHERE clause is used for filtering data before aggregation. So while WHERE isn't for aggregation, it has other uses. To filter data based on an aggregate function result, you must use the HAVING clause.

Which clause is that aggregate functions can be used in and which clause is that they cant be used in?

An aggregate function can be used in a WHERE clause only if that clause is part of a subquery of a HAVING clause and the column name specified in the expression is a correlated reference to a group. If the expression includes more than one column name, each column name must be a correlated reference to the same group.

What is an aggregate function?

An aggregate function is a mathematical computation involving a range of values that results in just a single value expressing the significance of the accumulated data it is derived from. Aggregate functions are often used to derive descriptive statistics.