Results 1 to 12 of 12
  1. #1
    brownk is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    May 2012
    Location
    Evansville, IN
    Posts
    56

    Another simple expression question!

    Hello everyone. I have a table and i need to know the sum of the "collateral" field. I have an applID (somtimes 2 or 3 of them each with different amounts). I need to know the sum of the collateral. I may have 3 different amounts for each applID. Thanks!

  2. #2
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    DSum("collateral", "tableName", "applID = whatever")

    http://www.techonthenet.com/access/f...omain/dsum.php

  3. #3
    brownk is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    May 2012
    Location
    Evansville, IN
    Posts
    56
    My query is set to run this expression for all entries in a given month so i wont really be stating any values/criteria for the applID. I just need all the values for "collateral" that have matching applID's to sum up.

  4. #4
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    Oh.
    SELECT applID, Sum(collateral) As SumOfCollateral
    FROM tableName
    GROUP BY applID

    That should give you one record for applID and the sum of all the collaterals per applID

  5. #5
    brownk is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    May 2012
    Location
    Evansville, IN
    Posts
    56
    okay. Should i make a table query for that SQL statement?

  6. #6
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    What exactly do you want to do with the Collateral Amounts per AppID?

    Unless we know what you are wanting to do, it is difficult to advise.

    And NO you should not put these Calculated values in a table. You can always calculate them in a query, as TheShabz has shown.

  7. #7
    TheShabz is offline Court Jester
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    1,368
    What Orange said. You should not store calculated values (with rare exceptions) in a table. They can always be done on the fly.

  8. #8
    brownk is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    May 2012
    Location
    Evansville, IN
    Posts
    56
    I figured this one out. Here is the SQL statement.

    SELECT dbo_tblCollateral.applID, Sum(dbo_tblCollateral.value) AS SumOfvalue
    FROM dbo_tblLoan RIGHT JOIN dbo_tblCollateral ON dbo_tblLoan.applID = dbo_tblCollateral.applID
    GROUP BY dbo_tblCollateral.applID;

    This is a seperate query, and its working fine. Im going to link this query with another to make a report. What i now need to do is take the SUM from this statement, and divide it by another field in a separate table. The only problem is sometimes the values are 0, so i get a divide by zero error. I have tried a couple expressions such as

    IIf([Divisor]=0,Null,[Dividend]/[Divisor])
    and
    IIf([Divisor]=0,0,[Dividend]/[Divisor])

    I cant get any to work. They say its not a part of an aggregate function, or when it does work it completley undoes my grouping that the SQL statement above preforms. Instead of having unique applID with the sum like i need, i get multiple applID's.

  9. #9
    brownk is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    May 2012
    Location
    Evansville, IN
    Posts
    56
    Attachment 7807Attachment 7808


    Maybe this will help in explaining my problem

  10. #10
    brownk is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    May 2012
    Location
    Evansville, IN
    Posts
    56
    @Orange - What i said in my original post. i needed to know the SUM.

  11. #11
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,848
    ?? Where/When did the RIGHT JOIN come into this?

    I think if you tell us in plain English what exactly is your situation and WHAT exactly you are wanting to do, the readers can offer advice or suggestions. When pieces get added, or show up in your code without any context for the rest
    of us, it seems we are only guessing at what you are trying to do.

    If any values in a DIVIDE operation are null or 0, you will get an error. Of course you could ignore the values that are NULL and/or 0, but since we don't have any idea of what they represent, we can not offer anything.

    As you are finding, it is difficult to get Access or any software to evaluate an expression, when you are not clear in What you are doing in business terms, and not clear on the commands in Access.

    Go back and read your post #1 -- you don't see any Right Joins or Division etc. We're trying to be helpful, so maybe you can help us by filling in some of the gaps.

  12. #12
    brownk is offline Advanced Beginner
    Windows 7 64bit Access 2003
    Join Date
    May 2012
    Location
    Evansville, IN
    Posts
    56
    The null values represent dollars. There will ocasionally be 0 values, thats somthing thats out of my control. Im building this query as i go along, but FIRST i had to get the SUM of a value stored in the COLLATERAL field (this is now done and working). We add up all the collateral, and compare that to the loan (AMOUNT) to find a loan to value percentage. There were no other tables during my first post because i had to get the SUM of the COLLATERAL field. Now ive added a LOAN table to finish my query. I now have a total of 2 tables. I believe that i am giving clear commands to access. Divide AMOUNT by LOAN, theres nothing complicated in my queries structure. Theres 2 tables, pulling from 3 fields. Sorry if it wasent plain enough english.

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

Similar Threads

  1. Easy expression question
    By brownk in forum Access
    Replies: 1
    Last Post: 05-18-2012, 04:30 PM
  2. An Expression Builder Question
    By ddkolb in forum Reports
    Replies: 3
    Last Post: 06-03-2011, 04:51 PM
  3. Simple VBA Question
    By koper in forum Access
    Replies: 1
    Last Post: 01-20-2011, 12:07 PM
  4. simple expression!
    By Lon in forum Access
    Replies: 1
    Last Post: 05-13-2010, 10:45 AM
  5. Simple Expression
    By Bridgid in forum Queries
    Replies: 7
    Last Post: 06-17-2009, 09:07 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