Add Counting Column

Background: 

This script will add a new column that will count the number of records based on a field that is selected by the user.

Documentation: 

This script will allow you to select a file and a field in which you want to count the items.  It will add a row and place the number of that particular entry.

If we use the ACCESS-Database.IMD that is used in the training we can see from the above that for the COUNTRY field we have Albania, Andorra and Angola.  We run the script and will get this dialog in which we select the file and the country field.

Once we run the script a new field called COUNT will be added and you will have the following:

So from the above example we see that we have 146 records for Albania, 2 for Andorra and at least 6 for Angola (actually 16).  This script will work on character, numeric, date and time fields.

Brian

Comments

Thanks for this, this is exactly what I was looking for, I knew I couldn't be the one wanting to do this so I decided to check this forum, wasn't disappointed :p
Thanks once again!

Brian Element's picture

Glad to help, let me know if you ever have any suggestions for scripts.

It is really helpful when I want to create a pivot table showing multiple registers for the same unique key, with this count I can display them as columns, for instance 2 people with same unique ID, I can list 1 register per unique key and list whatever as column.In regard to this, is there any way to create a Pivot Table with anything else beside a numeric as values?
Something like this
http://imgur.com/a/iQRrD

Brian Element's picture

You can drop non-numeric fields into the data but it only gives the count so I don't think that is what you are looking for.  So it is really limited to numeric fields at this time.

What version of IDEA was this written in? Will it work in version 10.x? Sorry for asking before trying. I have a script for calculating running balances that gives me errors when I try using it in version 10.x. I have not been able to modify it to work. This is very similar so I can adapt it if it works in 10.

Brian Element's picture

Hello ununtuai, yes I wrote this with version 10 so you should be able to adapt it for your needs.

Brian

Thanks Brian. Permit me to ask for more: In your free time (if any) could you add additional comments to explain what the various functions are doing?

Brian Element's picture

Hi ubuntuai,

I have added some comments, if there are any areas of the script you are not sure about please let me know and I will explain further.

Thanks

Brian