MS Access : Report Sorting by Count
Someone on StackOverflow had a question:
I've created an Access report that is grouped by a person identifier and then displays all the rows in the source query related to that person identifier. I want to sort my report output by the person with the least number of rows to the person with the most number of rows.
Here's the data:
They had 3 different PersonID.
id123456
id234567
id23456789
They wanted to sort by PersonID with the least amount of rows on top.
So I made a replica of their table called tbl_people (and I added p# at the end of each field to make sure the data was going to the right area of the report. so p1 is for Person1, p2: Person2, p3: Person3) -close and save-
Then using the Query Builder, I added tbl_people and added PersonID
TWICE. Click the totals button towards the top; then change the first column from Group By to Count
and make the Sort: Ascending
(and I ended up naming it qry_count) -close and save-
Make a report, Right click on the square in the corner, click on Report Properties,
Go to either the Data
or All
tab and click on the little three dots to the right of Record Source
Add tbl_people and qry_count. Then drag PersonID from qry_count to PersonID in tbl_people creating an equal join. Then add ALL fields from tbl_people, click totals (at the top of the Query Builder), set ID Sort: Ascending
. Then from qry_count add field CountofPersonID and make sure that is in the front of the query builder
On your report, add the fields (I added all of them from the table) then with the Sorting/Grouping (the same way you find the Report Properties) add a Group
and add a textbox in the header and make the Control Source
the CountOfPersonID. And that should do the trick! :)
(Copied and pasted my response from StackOverflow; has not been edited yet!)
Comments
Post a Comment