473,395 Members | 1,678 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to get a cumulative sum or count in MS Access from a Table?

99 64KB
In a table:
Expand|Select|Wrap|Line Numbers
  1. SID   Date         Status
  2. 1     25/8/2017     P
  3. 1     26/8/2017     P
  4. 1     27/8/2017     A
  5. 2     25/8/2017     A
  6. 2     26/8/2017     P
  7. 2     27/8/2017     A
  8. 1     01/9/2017     P
  9. 1     02/9/2017     A
  10. 1     03/9/2017     A
  11. 2     01/9/2017     P
  12. 2     02/9/2017     A
  13. 2     03/9/2017     P
  14. ......................
  15. ......................
  16. 1     01/10/2017     P
  17. 1     02/10/2017     A
  18. 1     03/10/2017     A
  19. 2     01/10/2017     P
  20. 2     02/10/2017     A
  21. 2     03/10/2017     P
  22.  
Where SID and Date are (combined) set as Primary Key.

The result required is:
Expand|Select|Wrap|Line Numbers
  1. SID  Status  Month    CountThisMonth  TotalCountPrevious
  2. 1     P      8/2017        2                0
  3. 1     A      8/2017        1                0
  4. 2     P      8/2017        1                0
  5. 2     A      8/2017        2                0
  6. 1     P      9/2017        1                2
  7. 1     A      9/2017        2                1
  8. 2     P      9/2017        2                1
  9. 2     P      9/2017        1                2
  10. .............................................
  11. .............................................
  12. 1     P      10/2017       1                3
  13. 1     A      10/2017       2                3
  14. 2     P      10/2017       2                3
  15. 2     P      10/2017       1                3
  16.  
Similarly, in the next month, the TotalCountPrevious should show the total count of all the preveous months. I am able to get CountThisMonth but not understanding how to get the other one. I got a method for that one by googling, that is, DCount or DSum, and it worked for me. But, however, it is a very very slow process and took too time to run the query or the report.
So I request for help. Thanking in advance....
Jan 8 '18 #1
1 2678
GazMathias
228 Expert 128KB
Hi mshakeelattari,

The solution is similar to what you have already implemented. You can use another DCount formula for the cumulative count but change its criteria such that it looks for dates prior to the row it is executing on and NOT equal to it like you are currently doing.

Expand|Select|Wrap|Line Numbers
  1. "[your date field] < #" & Format([your date field],"mm/dd/yyyy") & '#'
  2.  
The problem I see is that the data you posted above does not appear to be storing dates as actual dates so I feel you may to have to jump through a few more hoops before you can solve this particular problem and scale the solution properly in the future.


Gaz
Jan 9 '18 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Vladimir | last post by:
Hello, I have a table in MS Access database. It has one field (with BYTE datatype) that has several properties set in Lookup tab of table Design View. Display Control = Combo Box. Row Source...
3
by: Phil Rutter | last post by:
Hello All, I have about 700 word documents that have 2 tables one is static 4 colums x 5 rows the other is 5 colums x rows ranging from 2 to 100 what i wolud like to do is open the word doc....
6
by: Paul | last post by:
I was wondering if anyone has had an issue where using vba code to read an excel file and import the data into an access table some records are not imported from the excel file. It seems looking at...
2
by: Tom Loach | last post by:
After reviewing the messages on google and using the Access 2000 developers handbook I came up with the following code to add a field to an access table. I'm working in Access 2002, and the code...
15
by: MLH | last post by:
In this forum, under a different subject title, I have explored the following: I want to examine each procedure in my class modules and standard modules (A97) Since the other subject title was...
5
by: Daniel Wetzler | last post by:
Dear MS SQL Experts, I have to get the number of datasets within several tables in my MSSQL 2000 SP4 database. Beyond these tables is one table with about 13 million entries. If I perform a...
2
by: db2udbgirl | last post by:
If I perform a select count(*) from tred.order_delivery query will it internally perform a full table scan to determine the row count for the following scenario case 1: There is a primary key on a...
3
by: RLN | last post by:
Re: Access 2003/Oracle 9i I have an Access app that connects to an Oracle DB via OLEDB/VBA code (no DSN or ODBC) Queries against straight Oracle tables run fine. For this query, however,...
1
by: vdama | last post by:
Hi, I am using MS-Access as back end table for VB application. In the access table there are four columns as sno,productioncount ,percentage and totalcount. Here in prodcution count filed we have...
18
by: Ehsan arman | last post by:
I am using two recordsets for inputting data into an access table. I have used two loops for each recordset to do so. My intent is to read data into the table from an Excelsheet. My first recordset...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.