9 Replies Latest reply on Jul 16, 2009 9:41 AM by ChristianAntalics

# Finding Total Count of Items in a List

### Title

Finding Total Count of Items in a List

### Post

I have struggled with this for a while:  If I have a list of inventory items - thousands of them - and I want to get a total count for each item and return that count to a variable, what is the best way to do this?

To clarify, if I have this list:

widget1

widget2

widget2

widget3

widget1

widget1

I want to run a script that returns a variable (called \$counts) that containes the item names followed by how many of them I have.  Like this: widget1;3 | widget2;2 | widget3;1

I've been doing this by sorting the inventory list and looping down the entire thing counting as I go along, but it seems like there must be a better way.  Is there a way to introduce a summary calculation or something else that would make this process more natural?

Thanks!

• ###### 1. Re: Finding Total Count of Items in a List

Well you can look into the "fast summaries" technique by Mikhail Edoshin

http://www.kevinfrank.com/download/kf-fast-summary.zip

but why cant this just be handled with a simple straight sub-summary report grouped by inventory ID?

• ###### 2. Re: Finding Total Count of Items in a List

I can get the right numbers by a subsummary report, but is there a way to get those numbers into a variable?  If so, I don't know how.

I just checked out the Edoshin file, though, and that method definitely makes it significantly more effecient.  I'll see if I can duplicate it for my purposes.  Thanks.

• ###### 3. Re: Finding Total Count of Items in a List
This solution actually works really well.  It's much more efficient.  Ingeniously simple, too.  Thanks a lot!
• ###### 4. Re: Finding Total Count of Items in a List

crapples wrote:

I can get the right numbers by a subsummary report, but is there a way to get those numbers into a variable?  If so, I don't know how.

Set Variable [\$count; tablename::summaryfieldname]

Should do the trick. If you have sorted the found set so that the listed records are in groups with sub-totals and you want the sub-total, use the getsummary function.

• ###### 5. Re: Finding Total Count of Items in a List

I have found that the count() function sometimes returns a value that is one less than the actual count.

I haven't yet found any pattern to this, but it has been noticed a few times.

Has anyone else experienced this phenomenon?

• ###### 6. Re: Finding Total Count of Items in a List

Christian Antalics wrote:

I have found that the count() function sometimes returns a value that is one less than the actual count.

I haven't yet found any pattern to this, but it has been noticed a few times.

Has anyone else experienced this phenomenon?

Only when using it in an auto-enter calculation, and creating a new field that could/should be included in the count.

• ###### 7. Re: Finding Total Count of Items in a List
Your response is very interesting and I think you might be on to something... Do you have an example that might help illuminate?
• ###### 8. Re: Finding Total Count of Items in a List

Exactly as it sounds: a self-relationship table based on two non-unique fields, one an indexed calculation, the other, a date.  Auto-enter calculation to determine the # of similar records is: Count ( Self::Record_ID ) + 1

• ###### 9. Re: Finding Total Count of Items in a List
What is the best solution in your opinion?