Results 1 to 5 of 5
  1. #1
    fzxxx is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2020
    Posts
    7

    query with running totals

    Hello. I have this table
    Model year MonthYear_text CountOfID_W
    XXX 2014 08 1
    XXX 2014 08 9
    XXX 2014 08 11
    YYY 2016 01 2

    I need to have a cumulative total by model as, for example
    Model year MonthYear_text Expr1
    XXX 2014 08 1
    XXX 2014 08 10
    XXX 2014 08 21
    YYY 2016 01 2

    But I am not able to set up the right formula. Not sure which kind of criteria I should add.



    I am trying with

    SELECT [table].[Model year], [table].MonthYear_text, DSum("[CountOfID_W]","[table]","[MonthYear_text]<= [MonthYear_text]" & " And [Model year]=" & '[Model year]' & "") AS Expr1
    FROM table
    ORDER BY [table].[Model year], [table].MonthYear_text;



    Anybody could give me suggestions?
    Thank you
    F




  2. #2
    fzxxx is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2020
    Posts
    7
    Perhaps I have found. I need to add a auto-increment field to the starting table

    then I can use:

    SELECT [table].[Model year], [table].MonthYear_text, DSum("[CountOfID_W]","[table]","[ID]<=" & [ID] & " And [Model year]='" & [Model year] & "'") AS Expr1
    FROM table
    ORDER BY [table].[Model year], [table].MonthYear_text;

    Is it the only way ?
    Cannot I use [table].MonthYear_text instead of ID?

    Thanks for all comments
    F

  3. #3
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    try

    Code:
    SELECT [table].[Model year], [table].MonthYear_text, DSum("[CountOfID_W]","[table]","[MonthYear_text]<= '" & [MonthYear_text]" & "' And [Model year]='" & '[Model year] & "'") AS Expr1
    FROM table
    ORDER BY [table].[Model year], [table].MonthYear_text;
    This assumes the Model Year is text type field and not a numeric field

  4. #4
    fzxxx is offline Novice
    Windows 10 Access 2013 32bit
    Join Date
    Apr 2020
    Posts
    7
    Quote Originally Posted by Ajax View Post
    try

    Code:
    SELECT [table].[Model year], [table].MonthYear_text, DSum("[CountOfID_W]","[table]","[MonthYear_text]<= '" & [MonthYear_text]" & "' And [Model year]='" & '[Model year] & "'") AS Expr1
    FROM table
    ORDER BY [table].[Model year], [table].MonthYear_text;
    This assumes the Model Year is text type field and not a numeric field
    Thanks for your reply

    actually I get a syntax error in " & "'
    in bold in the expression below:

    SELECT [table].[Model year], [table].MonthYear_text, DSum("[CountOfID_W]","[table]","[MonthYear_text]<= '" & [MonthYear_text]" & "' And [Model year]='" & '[Model year] & "'") AS Expr1
    FROM table
    ORDER BY [table].[Model year], [table].MonthYear_text;

    I try to understand how all these delimiters work... but in case you have already some ideas...
    Thank you
    F

  5. #5
    CJ_London is offline VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,446
    my bad - remove the double quote here [MonthYear_text]" &

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

Similar Threads

  1. Replies: 5
    Last Post: 10-31-2019, 04:32 PM
  2. Replies: 6
    Last Post: 09-14-2015, 06:05 PM
  3. running totals
    By challenger in forum Access
    Replies: 5
    Last Post: 08-11-2014, 02:36 PM
  4. Running Totals in Access Query
    By CalvT in forum Queries
    Replies: 2
    Last Post: 01-10-2013, 03:27 AM
  5. Select query for running totals
    By asawadude in forum Queries
    Replies: 2
    Last Post: 10-07-2010, 03:41 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