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:


tbl_people


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-


enter image description here


Make a report, Right click on the square in the corner, click on Report Properties, 


enter image description here


Go to either the Data or All tab and click on the little three dots to the right of Record Source


 enter image description here


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


enter image description here

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! :)


Report design mode

enter image description here


(Copied and pasted my response from StackOverflow; has not been edited yet!)


Comments

Popular posts from this blog

Microsoft Access: Using Checkboxes on Form to Determine/Summarize Options in Combo box/Drop down on Different Form