Perform a calculation in a query

Please support our MS Access and FileMaker Pro advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2007
Posts: 2
Reputation: shar164 is an unknown quantity at this point 
Solved Threads: 0
shar164 shar164 is offline Offline
Newbie Poster

Perform a calculation in a query

 
0
  #1
Mar 7th, 2007
I can't figure out how to perform a calcuation in a query and have the result output for use in a chart within a report. Forgive me I'm a newbie
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 65
Reputation: cpopham is an unknown quantity at this point 
Solved Threads: 0
cpopham cpopham is offline Offline
Junior Poster in Training

Re: Perform a calculation in a query

 
0
  #2
Mar 11th, 2007
Okay, first things first. What type of calculation are you attempting to do in the query? Are you calculating across multiple fields? Please provide a little more information about the calculation and the table structure if any the calculated fields are based upon.

Chester
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 16,212
Reputation: jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all jbennet is a name known to all 
Solved Threads: 538
Moderator
Featured Poster
jbennet's Avatar
jbennet jbennet is offline Offline
Moderator

Re: Perform a calculation in a query

 
0
  #3
Mar 11th, 2007
i just did this for my coursework

in the Field: section under the queries design view you can tyupe things like this.

GPPerCentre: [num_candidates]*[payment_eachscript]

(where gppercentre is what the field will be called, and num_candidates and payment_eachscript are existing firlds in the query)
Last edited by jbennet; Mar 11th, 2007 at 7:14 pm.
If i am helpful, please give me reputation points.
Reply With Quote Quick reply to this message  
Join Date: Mar 2005
Posts: 65
Reputation: cpopham is an unknown quantity at this point 
Solved Threads: 0
cpopham cpopham is offline Offline
Junior Poster in Training

Re: Perform a calculation in a query

 
0
  #4
Mar 11th, 2007
You can also use queries to calculate fields from several tables, perform regular calculations, etc. You can also perform calculations inside a report based on grouping and that may be easier, but I need to know a little more about what the calculation is and the underlying table structure.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 5
Reputation: firstbateyboy is an unknown quantity at this point 
Solved Threads: 0
firstbateyboy firstbateyboy is offline Offline
Newbie Poster

Re: Perform a calculation in a query

 
0
  #5
Apr 23rd, 2009
Hey this helps me too - thanks.

Except a little difference for me: I'm wanting a calculation using a decimal constant as follows:
HomePremium: [HomeSum]*[0.00119371]

What I'm trying to do is auto calculate a house insurance premium based on the user input of a Sum Insured called HouseSum.

Eg: Enter $300,000 for HouseSum and the autocalculation in the query multiplies this by a constant (which I have chosen/invented for simplicity) giving the answer: $358.13

But MS Access wont accept my constant. It will multiply two fields easy enough, but not [field] * my [constant].

Where am I going wrong?
Cheers
Last edited by firstbateyboy; Apr 23rd, 2009 at 9:20 am.
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 195
Reputation: HI2Japan is an unknown quantity at this point 
Solved Threads: 21
HI2Japan HI2Japan is offline Offline
Junior Poster

Re: Perform a calculation in a query

 
0
  #6
Apr 23rd, 2009
Is your field called HomeSum or HouseSum? You have it written both ways in your question. Try it without putting [ or ] around your constant.
Who was the first person to look at a cow and say, "I think I'll squeeze these dangly things here, and drink whatever comes out!"
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 5
Reputation: firstbateyboy is an unknown quantity at this point 
Solved Threads: 0
firstbateyboy firstbateyboy is offline Offline
Newbie Poster

Re: Perform a calculation in a query

 
0
  #7
Apr 23rd, 2009
Originally Posted by HI2Japan View Post
Is your field called HomeSum or HouseSum? You have it written both ways in your question. Try it without putting [ or ] around your constant.
Thanks for your reply. Yes it should be HomeSum not HouseSum. But that wasnt my problem. I tried it without [] around my constant, but I still got a "syntax error in query expression 'tblHomeProp.0.011937*[HomeSum]' "

I have chosen (in the "table" field located under the expression) the table that contains the field "HomeSum". I assume I need this. This causes the syntax error. When I leave the "table" field blank then there is no syntax error. Whats the story?
firstbateyboy
Reply With Quote Quick reply to this message  
Join Date: Mar 2006
Posts: 195
Reputation: HI2Japan is an unknown quantity at this point 
Solved Threads: 21
HI2Japan HI2Japan is offline Offline
Junior Poster

Re: Perform a calculation in a query

 
0
  #8
Apr 26th, 2009
Check out this little sample I just made. Is this what you are trying to do?

Also, if you are creating the expression, then the table field should be left blank. The query will not add this data to your table nor is the new field you are creating in your table. It is basically just a display only look at it so you do not need to put in anything in the table field.
Last edited by HI2Japan; Apr 26th, 2009 at 7:20 pm.
Attached Files
File Type: zip Example.zip (7.8 KB, 11 views)
Who was the first person to look at a cow and say, "I think I'll squeeze these dangly things here, and drink whatever comes out!"
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 5
Reputation: firstbateyboy is an unknown quantity at this point 
Solved Threads: 0
firstbateyboy firstbateyboy is offline Offline
Newbie Poster

Re: Perform a calculation in a query

 
0
  #9
May 2nd, 2009
Thanks so much for your help - spot on!
I have shifted house this week so sorry for delay in replying... See ya!
Last edited by firstbateyboy; May 2nd, 2009 at 7:30 am. Reason: spelling
firstbateyboy
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC