Results 1 to 11 of 11
  1. #1
    chowing0823 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2015
    Posts
    5

    DSUM Running total by group

    Dear fellows:



    I have been trying to write a query to make a running total by groups, but I keep getting error in return. What's wrong with my code?

    Code:SELECT test.name, test.Date, test.amount, DSum("[amount]","[test]","[ID]<=" & [ID] & "And [name]=" & [name]) AS Expr1
    FROM test;

    fieldsField types
    ID Number
    Name Text
    Date Date/Time
    Amount Number


    Org. table
    ID Name Date Amount
    1 ABC 11/1/2014 20
    2 ABC 11/3/2014 60
    3 EEF 12/2/2014 40

  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,530
    The text field requires delimiters:

    DLookup Usage Samples
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    chowing0823 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2015
    Posts
    5
    Hi there:

    Thanks a bunch. I have changed the code, it returns values to me but it's not adding with the correct groupings. What gives?

    name Date amount Expr1
    ABC 11/1/2014 20 20
    ABC 11/3/2014 60 80
    EEF 12/2/2014 40 120

  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,530
    What's the expression now? Hopefully the reserved word "Name" isn't the problem, but shouldn't be since it's bracketed.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    chowing0823 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2015
    Posts
    5
    The expr1 returns running total for all of the records, regardless of the names. My objective is to start a new running total based on group. Any help would be much apperciated

    Objective:

    name Date amount Expr1
    ABC 11/1/2014 20 20
    ABC 11/3/2014 60 80
    EEF 12/2/2014 40 40


    current
    name Date amount Expr1
    ABC 11/1/2014 20 20
    ABC 11/3/2014 60 80
    EEF 12/2/2014 40 120

  6. #6
    chowing0823 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2015
    Posts
    5
    SELECT test.name, test.Date, test.amount, DSum("[amount]","[test]","[ID]<=" & [ID] & "And [name]=" & '[name]' &"") AS Expr1
    FROM test;

  7. #7
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    You have the quotes wrong. Try

    DSum("[amount]","[test]","[ID]<=" & [ID] & " And [name]='" & [name] & "'")
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  8. #8
    chowing0823 is offline Novice
    Windows 7 64bit Access 2007
    Join Date
    Feb 2015
    Posts
    5
    Paul:

    You are a true gentleman, thanks for providing me such detailed answers. Yes, the query now returns me with the correct values.

    Many thanks

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

  10. #10
    Fredo is offline Novice
    Windows 10 Access 2007
    Join Date
    Oct 2022
    Posts
    2

    Running sum

    I have the same situation, but doesn't work

  11. #11
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    5,007
    Quote Originally Posted by Fredo View Post
    I have the same situation, but doesn't work
    Please do not hijack someone else's thread.

    Post a new question and show what you have tried.

    'doesn't work' is about much use as a chocolate fireguard.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

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

Similar Threads

  1. Replies: 6
    Last Post: 11-05-2014, 03:00 PM
  2. Using dsum to return a cumulative total
    By tomnsd in forum Queries
    Replies: 7
    Last Post: 04-01-2013, 01:16 PM
  3. Replies: 4
    Last Post: 09-27-2012, 02:23 PM
  4. Replies: 3
    Last Post: 09-06-2012, 03:35 PM
  5. not correct running total in group
    By cmk in forum Reports
    Replies: 1
    Last Post: 12-06-2006, 05:56 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