I think that there's something missing from your calculation example as what you have posted would produce a syntax error.
Do you want to count all the records in your table with that value or all the records in your found set with that value?
There are a number of methods that can be used to get your count, from relationships that match only to the records with that specified values, to using ExecuteSQL, to using a filtered one row portal with a summary field in the portal row.
I want that if Im going to sort out my record using my drop down menu, it will summarize or give me the number of counts of each record.
Now, if i will sort it gives me a wrong number of counts of each code.
A summary report lists records grouped by a common value--such as all records with the same value in your Code field. A sub summary layout part and a summary field are then used to show the count or other sub total type summary value based on all records in each such group.
So this sounds like you want to sort (group) your records by a different field and thus get different counts in your summary report.
If you add the right sub summary layout parts, you need only change the sort order for your found set of records to see different sub summary parts and their sub totals become visible.
Here's a tutorial on summary reports: Creating Filemaker Pro summary reports--Tutorial