4 Replies Latest reply on May 22, 2016 8:44 AM by beverly

# Count [all Children] and [all Grandchildren] of [all Parents]

Hi,

I have defined one-to-many relationships between 3 occurrences: [Parents] - [Children] - [Grandchildren].

I perform complex searches in the context of [Parents].

Whenever I've performed such searches, I would love to display three different figures in [Parents]:

- the count of all records found in [Parents],

- the count of all [Children] related to all records found in [Parents],

- the count of all [Grandchildren] related to all records found in [Parents].

Just to be clear, I am not trying to display the number of [Children] and [Grandchildren] for each and every record in [Parents], but well the total number for all records found in [Parents].

Is there a way to do that? I would be very grateful for any help.

(I would love to do the same in [Children] and [Grandchildren], but I figure I will be able to replicate the solution to those contexts)

• ###### 1. Re: Count [all Children] and [all Grandchildren] of [all Parents]

Count(related::field) will work on several relationships away.

Count (parent) = all records in parent

Count (children) = all records related to parent

Count (grandchildren = all records related to grandchild through the child relationship.

Do you want to "add" all the grandchildren together for all the found parents? or ??

beverly

• ###### 2. Re: Count [all Children] and [all Grandchildren] of [all Parents]

What Beverly suggested will work, but only one a per-record basis, not for an entire found set.

My suggestion:

• create a summary field ListOf

• create an unstored calculation field, type text, that simply references this summary field

• use this to create a new relationship

Child_toCount::childPK = GrandChild_toCount::childFK

Now Count ( Child_toCount::childPK ), and Count ( GrandChild_toCount::grandChildPK )

Alternatively: create a script that hops to Child via Go to Related Record ( Child ; matching only ; match found set ; new window ), gets the found set and writes it somewhere (global \$\$var), then goes to the related set of GrandChild (without new window…), then closes the window.

1 of 1 people found this helpful
• ###### 3. Re: Count [all Children] and [all Grandchildren] of [all Parents]

Many thanks, beverly and erolst!

Yes, I am indeed looking for a solution encompassing the entire found set.

I will now try implement the approach suggested by erolst.

Many thanks again,

Edyas

• ###### 4. Re: Count [all Children] and [all Grandchildren] of [all Parents]

The Summary field (Count) will work in a list view, summary part sorted by the fields that need to "trigger" the count!.

NOTE: this is different from the calculated function Count().

beverly