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

Access and totals/sums query criteria

3
I have a query that lists
User id, transcation id (the unique value), the date, and the amount that in turn generates a report.

I created a form to enter in an amount parameter, for example everything over $500. Is it possible to have access add up all the amounts for each user id and pull only those user ids that are greater than $500 in total.

Example:
115, 001, 1/1/16, $450
115, 002, 2/1/16, $60
198, 003, 2/1/16, $550
126, 004, 2/1/16, $400

So I would want 115 & 198 pulled but not 126. However, right now only 198 would get pulled with a simple greater than criteria. I would still want the individual transcations listed on the report.
Nov 20 '16 #1
5 1119
PhilOfWalton
1,430 Expert 1GB
Your question is unclear. Are you saying that you want all users and their transactions where the total transaction is >= 500, or are you saying you want a report showing all users and transactions, and highlight those users & transactions where the total >= 500?

In either case, your starting point is
Expand|Select|Wrap|Line Numbers
  1. DSum("TransactionAmount","Transactions", "UserID = " & UserID)
  2.  
I am assuming that UserID is a long number in a table called "Transactions"

Phil
Nov 20 '16 #2
rsanna
3
Sorry, yes, I want a query that will list all users and their transactions where the sum total of those transactions is greater than 500.

So if someone has a transaction of $450 and of $60 they will show up, instead of only those with single transactions over $500.

I put this in the criteria for the Transaction Amount, but it just gives me every entry (and using > instead gives me nothing).

Expand|Select|Wrap|Line Numbers
  1. 500<DSum("TransactionAmount","Transactions","UserID = " & "UserID")
Nov 21 '16 #3
PhilOfWalton
1,430 Expert 1GB
Try this

Expand|Select|Wrap|Line Numbers
  1. SELECT UserID, TransactionAmount
  2. FROM Transactions
  3. WHERE ((DSum("TransactionAmount","Transactions","UserID = " & [UserID]))>=500)
  4. ORDER BY UserID;
  5.  
It may be worth bearing in mind that over the course of time, the total for any user is likely to increase until eventually the total will all be over $500 for most of your users.
You may need to think about additional restraints such as $500 in a month or $500 in a year

Phil
Nov 21 '16 #4
rsanna
3
I'm still getting an error code - Data type mismatch.

Expand|Select|Wrap|Line Numbers
  1. SELECT UserID, TransactionAmount
  2. FROM Transactions
  3. WHERE (((DSum("TransactionAmount","Transactions","UserID = " & [UserID]))>=500))
  4. ORDER BY UserID;

I don't know what could be causing the mismatch, because a simple greater than works just fine in the TransactionAmount. The UserID is weird as it always 6 characters in length, but if it is say "3" then it is really " 3". My source material is also coming from a Union query if that makes any difference.
Nov 21 '16 #5
PhilOfWalton
1,430 Expert 1GB
I assumed UserID was a number. If it's Text which you are implying then the SQL needs inverted commas (double quotes) round the UserID.
I prefer to use Chr$(34) which is the ascii code for double quotes so the SQL becomes:'

Expand|Select|Wrap|Line Numbers
  1. SELECT UserID, TransactionAmount
  2. FROM Transactions
  3. WHERE ((DSum("TransactionAmount","Transactions","UserID = " & & Chr$(34) & [UserID] & Chr$(34)))>=500)
  4. ORDER BY UserID;
  5.  
Phil
Nov 21 '16 #6

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

Similar topics

7
by: keliie | last post by:
Hello Just a quick question that I've spent a few hours trying to solve with no luck (although one would think this should be fairly easy). I have a form with a subform. The subform is based...
3
by: ericargent | last post by:
Hi I'm using Acces 2003 I have Query where the several parameters for the criteria are supplied from a form. One parameter source is a combo box. What I am trying to do is if: An item is...
3
by: sfrvn | last post by:
I have searched high and low and cannot find an answer to my problem. So now I turn to the collective genius of this newsgroup. Over-simplified examples This query criteria for field works:...
2
by: cmartin1986 | last post by:
First of all I want to thank all of you that have helped me in the past this is an awesome fourm. My problem today is I have a database that builds charts that are viewed by a large group every...
4
by: tbeers | last post by:
Is there a method to pass along a criteria argument directly to the query criteria rather than through filtering a form or report? In other words, I would like to click a "print" button and in the...
8
by: limperger | last post by:
Hello everyone! First and foremost, my apologies for the title of the post. It is not very clarifying of what the problem is about, but I didn't know how to put it... My problem is as follows: I...
17
by: sharsy | last post by:
Hello guys, I would like some help in generating query criteria that will identify credit cards that have expired on an access database. The specific Field is formatted with a Data Type of...
30
by: DH22 | last post by:
Access 03 I'm currently having an issue using Dlookup when trying to reference a query (criteria syntax) Currently I have 1 table, which is L_Emps (which contains Employee_ID as my key...
9
ajhayes
by: ajhayes | last post by:
Hello everyone, This is my first time posting here and I'm hoping someone can help me out. I'm a relative newbie to Access and am pretty much learning as I go along, so please bear with me. ...
1
by: Goss | last post by:
I have added to the query criteria, and the query runs fine, but when I open the Chart in print view the input box asks me for the month 3 times? any ideas
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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,...

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.