Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7080417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T06:47:34+00:00 2026-05-28T06:47:34+00:00

I have a table with the following columns: reportDate DATETIME and losses CURRENCY and

  • 0

I have a table with the following columns: reportDate DATETIME and losses CURRENCY and of course the ID column.

How do I write a query that will return a table with a running total of the losses column? Each date will have multiple entries so i think they will need use Sum() for each date. I know this has to do with the DSum function but im still lost on this one. It should look something like

Month   Losses   Cum
-----   ------   -----
Jan     $3,000   $3,000
Feb     $2,000   $5,000
Mar     $1,500   $6,500

Having a sql statement that’s not Access specific would be the most help to me, I think. But all solutions are appreciated. Thanks for the help.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T06:47:35+00:00Added an answer on May 28, 2026 at 6:47 am

    I found table and field names in the edit history of your question, so used those names in this answer. You didn’t provide record_matYields sample data, so I created my own and hope it is suitable:

    id reportDate gainOrLoss
     1 12/28/2011  $1,500.00
     2 12/29/2011    $500.00
     3 12/30/2011  $1,000.00
     4   1/2/2012     $10.00
     5   1/3/2012  $4,500.00
     6   1/4/2012    $900.00
    

    First I created qryMonthlyLosses. Here is the SQL and the output:

    SELECT
        Year(reportDate) AS reportYear,
        Month(reportDate) AS reportMonth,
        Min(y.reportDate) AS MinOfreportDate,
        Sum(y.gainOrLoss) AS SumOfgainOrLoss
    FROM record_matYields AS y
    GROUP BY
        Year(reportDate),
        Month(reportDate);
    
    reportYear reportMonth MinOfreportDate SumOfgainOrLoss
          2011          12      12/28/2011       $3,000.00
          2012           1        1/2/2012       $5,410.00
    

    I used that first query to create another, qryCumulativeLossesByMonth:

    SELECT
        q.reportYear,
        q.reportMonth,
        q.MinOfreportDate,
        q.SumOfgainOrLoss,
        (
            SELECT
            Sum(z.gainOrLoss)
            FROM record_matYields AS z
            WHERE z.reportDate < q.MinOfreportDate
        ) AS PreviousGainOrLoss
    FROM qryMonthlyLosses AS q;
    
    reportYear reportMonth MinOfreportDate SumOfgainOrLoss PreviousGainOrLoss
          2011          12      12/28/2011       $3,000.00 
          2012           1        1/2/2012       $5,410.00          $3,000.00
    

    Finally I used qryCumulativeLossesByMonth as the data source in a query which transforms the output to match your requested format.

    SELECT
        q.reportYear,
        MonthName(q.reportMonth) AS [Month],
        q.SumOfgainOrLoss AS Losses,
        q.SumOfgainOrLoss +
            IIf(q.PreviousGainOrLoss Is Null,0,q.PreviousGainOrLoss)
            AS Cum
    FROM qryCumulativeLossesByMonth AS q;
    
    reportYear Month    Losses    Cum
          2011 December $3,000.00 $3,000.00
          2012 January  $5,410.00 $8,410.00
    

    You could probably revise this into a single query using subqueries instead of the separate named queries. I used this step-wise approach because I hoped it would be easier to understand.

    Edit: I returned the full name with the MonthName() function. If you want the abbreviated month name, pass True as a second parameter to that function. Either of these should work:

    MonthName(q.reportMonth, True) AS [Month]
    MonthName(q.reportMonth, -1) AS [Month]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have a table with the following columns: Qty, INTEGER SaleDate, DATETIME
I have a table that contains the following columns: ID int, DISTANCE float, EVENT
I have a table with the following columns id, teamA_id, teamB_id Will it be
I have a table called activity that uses the following columns: LoginDate, LoginID, Department,
i have a table that has the following columns: Team Region Person Name and
I have a table that has following columns id store_id store_name id and store_id
I have a table that has the following columns table: route columns: id, location,
Lets say I have table with following columns 1. Client - string. 2. Profit
I have a table with following columns: ContractorId ......... INT ............. IDENTITY ContractorName ........
I have a table with the following columns in SQL Server: MEMBERID, MEMBEREMAIL, FATHEREMAIL,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.