Results 1 to 7 of 7
  1. #1
    NoOoN is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    4

    Question How to do subtract in Query

    I have a queastion that : how much credit dose each customer still have available?



    I think the table I have to chose are : ( customet table wich have the credit limit) and ( Sales table which have the Amount of each customer spent)

    when do this formula : Credit Available: sum([Customer]![Credit limit]-[Sales]![Amount])

    It dosn't give the right answer

    help me please

    here is the file

    http://www.mediafire.com/?grwhmsyzu2a04qp

  2. #2
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    First create a field to sum the credit limit...call it CreditLimit (no spaces in field names is preferred). Next create a field to sum the sales amount....you can call it salesAmount or whatever you prefer. Now add a new field called CreditAvail. It will look like CreditAvail: [CreditLimit] - [salesAmount]. Use the group on expression for this field.

  3. #3
    NoOoN is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    4
    Thank you kennejd

    look to what I do







    and when I do run, it gives me this message



    I keep it blank

    and this is the ruslt


    what is the wrong in my steps?

  4. #4
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    I guess my explanation was confusing...

    You need to have separate columns that sum your credit amount and sales amounts. Then a 3rd column to do you calculation. Unfortunately I can't send you a screen shot...but if you pasted the following in the SQL view of your query, I think you'll be very close. For future reference, using spaces in table and field names is bad practice...

    SELECT
    [Customer Number]
    ,sum(Credit Limit) as CreditLimit
    ,sum(Amount) as SalesAmt
    ,[CreditLimit] – [SalesAmt] as CreditAvail
    FROM Customer c
    INNER JOIN Sales s
    ON c.[Customer number] = s.[Customer number]
    GROUP BY
    [Customer Number]

  5. #5
    NoOoN is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    4
    Thanx kennejd

    I do it by design veiw and it works


    The subtract is done

    but I don't know if there is a mistake?!

    because the customer number 1000, his credit limit is 2500 and he do three sales which it cost him 3129.7

    here the query sum the three times for the limit!

    It must be shown as zero or in minus!

    and thank you so much for your help =)

  6. #6
    kennejd is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Mar 2011
    Posts
    188
    I see the problem....instead of a sum you need to use max or min for the credit limit column. Be sure to rename your columns or you will get 'SumOfCredit'...'SumOfAmount'. Rename by putting Credit: in front of the field name.

  7. #7
    NoOoN is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Apr 2011
    Posts
    4
    Thank you so much

    it is work

    =)

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Subtract from inventory
    By NISMOJim in forum Access
    Replies: 5
    Last Post: 01-30-2011, 01:09 PM
  2. Subtract From Previous Record Using a Date
    By txrules in forum Queries
    Replies: 1
    Last Post: 12-30-2010, 02:10 AM
  3. Replies: 9
    Last Post: 03-19-2010, 10:37 AM
  4. Subtract Rows in Query Results
    By Sengenbe in forum Queries
    Replies: 5
    Last Post: 02-08-2010, 06:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums