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

How to Sum and Divide two columns in a query

I found that there is something like Sum([col 1]), and I get that....

I have two columns that are populated via check boxes on the form called 'Sent' and 'Signed'. Once checked, the value in the table is a -1.

I need to divide the total sums to get a percentage of signed vs. not signed.

In Access, what would be the formula I enter in the query field (named %Completed) I made to display the answer? I tried:

%Completed:Sum([Signed])/Sum([Sent])

That doesn't work!

There is a need to display the %Compeleted result on the form. The result should be the % for ALL items on the form, so no matter which Supplier I scroll to, the % value does not change. And as I select and/or deselect between the Signed and Sent check boxes on each supplier, the % will update.

Is this confusing??
Jul 23 '10 #1
20 30844
NeoPa
32,556 Expert Mod 16PB
FaurKris: Is this confusing??
Absolutely (You asked)! I'm afraid you started somewhere in the middle and never got around to telling us much about the query you're working on.

Is it a GROUP BY query?

It would probably help if you posted the SQL for it to give us a clue as to what we're working with.
Jul 23 '10 #2
@NeoPa
I'm very Green when it comes to Access.....

Maybe if I try to explain it differently???

I am querying customers information on a form. The form simply shows their contact information and allows me to add/edit the information. Then of course I can plot a report!

Well, I want to add to my form - a reference for me.

What I want to add are two check boxes and a text box which will display a math formula.

One check box is to indicate if I have sent my customer a notice. The other check box is to indicate if that same notice was sent back to me and signed.

The formula I need to display is the percentage of returned notices (Signed/Sent).

Just like many forms, I can use the scroll button on my mouse and scroll thru the whole list of my customers. As I do that, I can see which ones I have sent a notice to and which ones have returned their notice via the check boxes. And these I already have which are working just fine.

What I need help with is being able to see the percentage of returned notices (text box?) regardless of the customer I am viewing on the form.

I DO NOT NEED TO PRINT THIS INFORMATION TO THE REPORT. For my viewing pleaseure only.

Currently I do this in excel, which is a pain because I am having to update two lists of customer information that way....


I dont know how to post a SQL or what that really is... lol.

Any clearer?? I hope so!
Jul 26 '10 #3
NeoPa
32,556 Expert Mod 16PB
That does make it a little clearer. Shame about the SQL, but let's see what we can do without it for now.

Forms have Header and Footer sections as well as the Detail section you're probably used to working within (even if you've never noticed it). If your form shows no Header or Footer section when in Design View, then it is probably a simple case of that not showing. To show these sections toggle Form Header/Footer from the View menu.

I would create a TextBox control in your (now visible) Footer section and set its Control Source to something like :
Expand|Select|Wrap|Line Numbers
  1. =Sum(IIf([ReturnedNotices],1,0)/(Sum([Sent],1,0)+IIf(Sum([Sent],1,0)=0,1,0))
I don't know the names of your controls so you may need to substitute your names for these.
Jul 26 '10 #4
@NeoPa
Cool! You understand what I need to do...

When I paste the code (after right clicking the text box/Properties/Data/Control Source/pasting the code in the empty box and clicking ok) I get an error saying "The expression you entered has a function containing the wrong number of arguments."

I should say that I deleted the "ReturnedNotices" text that was already in the control source dialog box before pasting your code.

I tried it without deleting the existing text and was told that I am "missing an operand, invalid character, missing quotes."

What did I do wrong???


And thanks for helping!!!
Jul 26 '10 #5
Attached screen shot. Maybe this will help too?
Attached Images
File Type: jpg SCRNSHOT.jpg (19.8 KB, 1556 views)
Jul 26 '10 #6
Didn't know it would reduce the picture by so much....
Attached Images
File Type: jpg SCRNSHOT1.jpg (20.3 KB, 1032 views)
Jul 26 '10 #7
NeoPa
32,556 Expert Mod 16PB
Unfortunately, the resolution is too low for me to get much of meaning I'm afraid.

What I can see of the second screenshot is that it says :
Expand|Select|Wrap|Line Numbers
  1. Something=Blahblahbla
instead of :
Expand|Select|Wrap|Line Numbers
  1. =Blahblahbla
as shown in my post.

Perhaps posting the actual text of what you tried would help us to make progress.
Jul 26 '10 #8
NeoPa
32,556 Expert Mod 16PB
Forget that last post. I so rarely work in Design View I'm a little rusty.

You probably want :
Expand|Select|Wrap|Line Numbers
  1. Completed: Sum(IIf([ReturnedNotices],1,0))/(Sum(IIf([Sent],1,0))+IIf(Sum(IIf([Sent],1,0))=0,1,0)))
PS. Updated as I found the formula had a bunch of mistakes in it anyway. Apologies for my sloppy post.
Jul 26 '10 #9
@NeoPa
This is what I tried first, "=Blahblahbla "
Expand|Select|Wrap|Line Numbers
  1. Completed: Sum(IIf([Signed],1,0))/(Sum(IIf([Sent],1,0))+IIf(Sum(IIf([Sent],1,0))=0,1,0)))
I am now only getting an operand error. I'm missing a parenthesis somewhere? I'm trying to understand exactly what the formula is doing so I can figure it out.... lol.
Jul 26 '10 #10
NeoPa
32,556 Expert Mod 16PB
I've got it now. Doh! There was an extra closing parenthesis even in the last version.

Try this :
Expand|Select|Wrap|Line Numbers
  1. Completed: Sum(IIf([Signed],1,0))/(Sum(IIf([Sent],1,0))+IIf(Sum(IIf([Sent],1,0))=0,1,0))
It's basically saying check each value of [Signed] and return a 1 where checked and a 0 where unchecked. Next Sum all these values for the value A. It's also saying the same except with [Sent] for B. From there the formula is :
Expand|Select|Wrap|Line Numbers
  1. Completed: A/(B+IIf(B=0,1,0))
Jul 26 '10 #11
@NeoPa
I appreciate all your help!

I am still getting an operand type error regardless of what I do....

I'm unsure exactly how to procede! I've probably got something else wrong somewhere...


Thanks again!
Jul 28 '10 #12
@NeoPa
This is what comes up when I enter the code directly into the Query. Vendor Data is my Table...
Attached Images
File Type: jpg untitled.jpg (51.9 KB, 677 views)
Jul 28 '10 #13
NeoPa
32,556 Expert Mod 16PB
How about you pop the actual formula you used as text in the post. Trying to work from a tiny picture of an error message pop-up is not good.
Jul 28 '10 #14
Sorry. I used teh exact code you posted.
Expand|Select|Wrap|Line Numbers
  1. Completed: Sum(IIf([Signed],1,0))/(Sum(IIf([Sent],1,0))+IIf(Sum(IIf([Sent],1,0))=0,1,0))
I also tried Googling and making small changes and such. I even verified the names of the columns. There is Sent, Signed and Completed. So to get a percent completed, I need to sum and divide Signed by Sent.

I feel like a 4th grader! Haha! Too bad I cant just use Excel...
Jul 28 '10 #15
NeoPa
32,556 Expert Mod 16PB
Are you sure this is the actual code that gave that error?

I've gone through it again with a fine-toothed comb and it looks perfect to me. If that's the exact code then I don't know what it's complaining about.
Jul 28 '10 #16
Within my form:
I right click the text box for the field "Completed".
Enter into Properties.
Click Data.
Click the 3 little dots next to Control Source.
Delete the word "Completed" that is in the dialog box and paste your code - compeltely.
Then I click OK.

If I click off the Control Source slection, a dialog pops up saying "The expression you entered has invalid syntax. You may have entered an operand without an operator."

If I simply close the properties menu, the code I pasted in there is erased or something. I know this because when it didn't work, I reopened properties and the code is gone...


Now, because the check boxes produce a negative 1 within the table/query, I altered the formula to show that too...

Like I said, I do appreciate your assistance. If it cannot be solved I will just have to try and think of another way...
Jul 28 '10 #17
NeoPa
32,556 Expert Mod 16PB
I'll tell you what. Drop a copy of your database as an attachment and I'll look at it for you. I'll need instructions as to where to look of course. I'll also include some instructions I've used before indicating how best to go about attaching a database.

When attaching your work please follow the following steps first :
  1. Remove anything not relevant to the problem. This is not necessary in all circumstances but some databases can be very bulky and some things do not effect the actual problem at all.
  2. Likewise, not entirely necessary in all cases, but consider saving your database in a version not later than 2003 as many of our experts don't use Access 2007. Largely they don't want to, but some also don't have access to it. Personally I will wait until I'm forced to before using it.
  3. If the process depends on any linked tables then make local copies in your database to replace the linked tables.
  4. If you've done anything in steps 1 to 3 then make sure that the problem you're experiencing is still evident in the updated version.
  5. Compile the database (From the Visual Basic Editor select Debug / Compile {Project Name}).
  6. Compact the database (Tools / Database Utilities / Compact and Repair Database...).
  7. Compress the database into a ZIP file.
  8. When posting, scroll down the page and select Manage Attachments (Pressing on that leads you to a page where you can add or remove your attachments. It also lists the maximum file sizes for each of the allowed file types.) and add this new ZIP file.
It's also a good idea to include some instructions that enable us to find the issue you'd like help with. Maybe some instructions of what to select, click on, enter etc that ensures we'll see what you see and have the same problems.
Jul 28 '10 #18
@NeoPa
Form. At the bottom, Completed.
Although the form, in this state, has all the information removed, you can still scroll thru. There are already some check marks... Filling in the Completed box with the percentage of Sent AND signed is the goal. So when I begin, most of the customers are checked with a SENT. The Completed percentage will be 0%. As the SIGNED copies come back and I check that box, the percentage will rise.

A just thought of another caveat! Darnit!!

Each Desitnation Plant is seperate. So the Sent, Signed, and Completed fields are dependant on the plant... Example, I may have 47 plant ONE and only 3 plant FOUR. So the 'Completed' feild needs to somehow read which 'FIS Destination Plant' is selected and show the percentage just for those.... Is that even possible? I would guess there aould be an additional IF/THEN statement somewhere.

This way, I can see a percentage of Signed for each of the 6 plants...

Make sense? Sorry, this last part just occured to me... lol.
Attached Files
File Type: zip Routing Instructions.zip (42.3 KB, 162 views)
Jul 29 '10 #19
NeoPa
32,556 Expert Mod 16PB
I'll download when I get home and then all you say will make much better sense to me. I'll post later with any thoughts or help I come up with.
Jul 29 '10 #20
NeoPa
32,556 Expert Mod 16PB
A few things to start with are :
  1. The footer section, as with the header section when used, is for unbound controls. Controls that can reflect totals of various items across many records. The detail section is for showing details of the current record.
  2. The [Completed] control cannot be populated by the query. I had no idea you were trying to work along such lines (having detailed info along with totals info in the same query). It really makes no logical sense at all I'm afraid. We will need to look at this again from scratch. Probably some AfterUpdate processing but we'll get to that when I've seen your reaction to this post.
  3. As for your caveat, this makes life a little more complicated it's true, but probably handlable as we know the requirement. I'd suggest the plant name be redisplayed in the Footer along with the calculated field though. As a more friendly interface rather than program logic.
I'm afraid what I saw of your database rather makes what was discussed before all pretty redundant. This is not the end of the world though. We can rebuild it, but it would be somewhat different that's all (and possibly take a bit longer).

Let me know what you think of what I've said so far.
Jul 29 '10 #21

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

Similar topics

1
by: knoak | last post by:
hi there, A few days ago i posted a question how i could divide a query's result over 2 collumns. I got the following code thanks to Pedro: > echo '<table class="search_result"...
2
by: Gunne | last post by:
I need to divide my XML data into 4 columns. The LinkCategory name need to be shown as header and then the LinkName(s) that belong to the LinkCategory underneath. Please help me with an XSLT...
10
by: rong.guo | last post by:
Greetings! Please see my data below, for each account, I would need the lastest balance_date with the corresponding balance. Can anyone help me with the query? Thanks a lot! create table a...
5
by: Otie | last post by:
I have a select query that groups records together, specifically baseball players and their home runs and at-bats. I want to create a query that displays , , and and that sorts ASCENDING on the ...
1
by: mike | last post by:
Does anyone know if this is feasable I have two tables one has inv_id,amount,date, cheque no the second has inv_id, amount , code (this relate to type of expenditure) There is a one to...
4
by: Andy M | last post by:
Hi what I am trying to do is this: I have this: Family Names ¦ First Names _______________________ Family Name1 ¦ First Name1 Family Name1 ¦ First Name2
6
by: john | last post by:
I'm trying to do something that I thought was simple but has already taken me hours. I'm trying to use a value from an unbound date field in a query. Amongst others I tried the following, but I...
2
by: ielamrani | last post by:
Hi, this is very strange. I am trying to add 2 columns in a query but it does not come out right. Column1 Column2 Column3 $15.00 $30.00 $15.00$30.00 Column3 should equal $45.00. ...
9
by: yaaara | last post by:
Guys, I keep landing into problems (Good for me as I'm learing a lot from this) and here is another one for the brainy ones: I have the following query that I need to execute in Access VBA ...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
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...

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.