Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103

    Summing a sum function

    I have two sum values



    =DSum("TOTALJOB_COST","Table2","[Job#] = '" & [Job#] & "'")

    and

    =DSum("QUOTATION_COST","Table1","[Job#] = '" & [Job#] & "'")



    What is SQL to Aggregate both of these values?

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    How about:

    =DSum("TOTALJOB_COST","Table2","[Job#] = '" & [Job#] & "'") + DSum("QUOTATION_COST","Table1","[Job#] = '" & [Job#] & "'")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @pbaldy

    Thank you! That works!

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Happy to help!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @pbaldy

    One final question. What would be the expression to get % Gross Margin, if:

    Gross Margin is:
    =DSum("TotalQuote","Table1","[Job#] = '" & [Job#] & "'")-DSum("TOTALJOB_COST","Table2","[Job#] = '" & [Job#] & "'")-DSum("QUOTATION_COST","Table1","[Job#] = '" & [Job#] & "'")

    and, Total Cost is:

    =DSum("TOTALJOB_COST","Table2","[Job#] = '" & [Job#] & "'")+DSum("QUOTATION_COST","Table1","[Job#] = '" & [Job#] & "'")

    I am not familiar with the division process...

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Not sure where you're stuck. The operator for division is /, so

    =(DSum(...) - DSum(...)) / (DSum(...) + DSum(...))

    Note the parentheses to force the addition/subtraction before the division.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @pbaldy

    Great, that works. Thank you. I need to start learning SQL...

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problemo!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    &pbaldy

    One other question. I am trying to string together the "Business Name" and "Job#" into an expression.

    My String has a syntax error, and I don't know what it is. Can you provide the correct expression?

    BUSINESS NAME: ("BUSINESS NAME","Table1","[Job#] = '" & [Job#] & "'") & " " & ("Job#","Table1","[JoB#] = '" & [Job#] & "'")

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Are those meant to be DLookup() formulas? If so, you forgot the DLookup part. Also, if that's in a query, you'd normally get the info by joining the tables, not a DLookup().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @pbaldy

    Yes, this in a query but I am stumped by the duplicate name Business Name and that the Job# can be associated with many Business Names. So, I wanted to create a SQL expression and that is where the syntax error comes in. Not sure about DLookup. I'm just starting to poke around into SQL...

  12. #12
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Well, if the table (table1) is joined in the query, simply:

    BUSINESS NAME: [BUSINESS NAME] & " " & [Job#]

    What you have is like the syntax of a domain aggregate function without the actual function name. It would look like:

    BUSINESS NAME: DLookup("BUSINESS NAME","Table1","[Job#] = '" & [Job#] & "'") & " " & DLookup("Job#","Table1","[JoB#] = '" & [Job#] & "'")

    But again, it is unusual and inefficient to use DLookup() in a query. You'd normally join table1 to whatever other table(s) is involved and get the values the first way.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  13. #13
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    Click image for larger version. 

Name:	ACCESS FORUM.JPG 
Views:	17 
Size:	74.6 KB 
ID:	42001

    @pbaldy

    OK, making progress but I am getting an error regarding Job# could be located in other tables, although I am specifying Table1 in the Query. How can I be more specific?

  14. #14
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    Sorry, should have thought of that.


    BUSINESSNAME: table1.[BUSINESS NAME] & " " & table1.[Job#]

    By the way, the spaces and symbols in your names are more trouble than they're worth in the long run.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  15. #15
    zkrucz is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Oct 2016
    Posts
    103
    @pbaldy,

    That works great now! thank you!

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Summing Nulls
    By mindbender in forum Queries
    Replies: 13
    Last Post: 11-28-2017, 01:38 PM
  2. Summing Multiple Queries & Summing Time
    By WEJ in forum Queries
    Replies: 2
    Last Post: 10-04-2013, 04:46 PM
  3. summing in a query
    By nparrillo in forum Queries
    Replies: 1
    Last Post: 04-11-2011, 10:37 AM
  4. summing
    By nashr1928 in forum Forms
    Replies: 18
    Last Post: 04-05-2011, 05:01 PM
  5. Summing reports
    By tarhim47 in forum Reports
    Replies: 0
    Last Post: 03-30-2011, 11:07 AM

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