?
Solved

running count of unique values in a ms access report

Posted on 2013-11-05
4
Medium Priority
?
2,662 Views
Last Modified: 2013-11-17
I have a table that has a list of numbers that i would like to display a running count of unique value in a ms access report, this report has no grouping levels which makes it a bit challenging.Thanks
Database1.accdb
0
Comment
Question by:Svgmassive
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 10

Expert Comment

by:etech0
ID: 39625129
For a list of unique values:

SELECT DISTINCT fieldName FROM tableName;

For a count of unique values:

SELECT Count(*) AS N
FROM
(SELECT DISTINCT fieldName FROM tableName) AS T;
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39625133
is this what you are looking for

SELECT dbo_itemx.Sequencenumber, Count(dbo_itemx.Sequencenumber) AS CountOfSequencenumber
FROM dbo_itemx
GROUP BY dbo_itemx.Sequencenumber;

or maybe this is what you need

SELECT Q.Sequencenumber,
(select count(*) from
(SELECT dbo_itemx.Sequencenumber
FROM dbo_itemx
GROUP BY dbo_itemx.Sequencenumber
)  as Q1 where Q1.SequenceNumber<=Q.SequenceNumber) AS Expr1
FROM
(SELECT dbo_itemx.Sequencenumber
FROM dbo_itemx
GROUP BY dbo_itemx.Sequencenumber
) as Q;



it will help if you post a desired outcome/output
0
 
LVL 48

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 39625235
You could use a function, see fnUniqueRowCount() in the attached database.

Add a control to your report, set the ControlSource to:

=fnUniqueRowCount([UniqueFieldName])

Then, change the Hide Duplicates (towards the bottom of the Format tab on the Properties dialog form) property to Yes.

Then, to make sure this works in normal view, report view, and print preview, you will need to call the function from the Report Open and Report Footers Format events, with the following code:

=fnuniquerowcount(Null,True)

This will reset the counter when the report is opened or when the report footer is formatted.  The reason for the latter is that when you view the report in print preview, it runs through the report twice and if you don't reset the counter at the end of the report, the numbers will start a the last number + 1
UniqueRowCount.accdb
0
 

Author Comment

by:Svgmassive
ID: 39628243
fyed that's what i am looking,but a strange this is happening if i hide the control and hide duplicates the count is not correct.i just need it to display a total in the page footer per page
0

Featured Post

Office 365 Training for IT Pros

Learn how to provision tenants, synchronize on-premise Active Directory, implement Single Sign-On, customize Office deployment, and protect your organization with eDiscovery and DLP policies.  Only from Platform Scholar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article helps those who get the 0xc004d307 error when trying to rearm (reset the license) Office 2013 in a Virtual Desktop Infrastructure (VDI) and/or those trying to prep the master image for Microsoft Key Management (KMS) activation. (i.e.- C…
Ever wonder what it's like to get hit by ransomware? "Tom" gives you all the dirty details first-hand – and conveys the hard lessons his company learned in the aftermath.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question