Results 1 to 3 of 3
  1. #1
    Sck is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    82

    How to sum at levels in a query

    I have two tables in my database, one contains the fields I need to total by and the other has the amounts to total. Easy enough to begin with but the trick is the key between the tables are not exact.



    Example:
    SumByTable Key
    1.0
    1.1
    1.1.1
    1.1.2
    1.2
    1.2.1
    2.0
    2.1
    2.2


    ActualDataTable Key
    1.1.1.1 $1.00
    1.1.1.2 $1.00
    1.1.1.3 $1.00
    1.1.2.1 $2.00
    1.1.2.2 $2.00
    1.2.1.1 $3.00
    2.1 $5.00
    2.2 $5.00

    I need to be able to pull the data summed at every level so my result will look like this:
    1.0 $10.00
    1.1 $7.00
    1.1.1 $3.00
    1.1.2 $4.00
    1.2 $3.00
    1.2.1 $3.00
    2.0 $10.00
    2.1 $5.00
    2.2 $5.00

    I have been trying to use the left function to trim the key in the actual data table but I have not been able to get it to work. If it is at the x.0 level then anything starting with the x needs to be summed.

    Any help is greatly appreciated! ps sorry about the spacing on the data above, it kept moving the $ left when I posted.

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    1 change x.0 to x
    Qry1: select iif(right(key,2)=".0",left(key,len(key)-2),key) from sumByTable

    2 sum by group
    select a.kkey,sum([data]) as summ from qry1 as a inner join actualData as on a.kkey=left(b.key,len(a.kkey) group by a.kkey

  3. #3
    Sck is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Jul 2010
    Posts
    82
    got it!! thanks

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

Similar Threads

  1. Login and user levels
    By seanog2001 in forum Forms
    Replies: 0
    Last Post: 10-27-2009, 05:13 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