# Can a field count how many records in a portal?

This topic is 7509 days old. Please don't post here. Open a new topic instead.

## Recommended Posts

I have a number of records appearing in a portal. I need to have the computer tell me how many records are in that portal. How can I do that?

Thank you!

##### Share on other sites

Define an unstored calculation field with a number result as:

= Count(YourRelationship::AnyRelatedField)

-bd

##### Share on other sites

So cool. Thank you very much! Works great.

##### Share on other sites

Hi Wes,

Not to correct, but to clarify:

quote:

Originally posted by LiveOak:

Define an unstored calculation field with a number result as:

= Count(YourRelationship::AnyRelatedField)

-bd

Make sure that "AnyRelatedField" is any field that is non-null / not empty. Best practice is to always use the target key field, because you know by default that it is not empty (since it shows up in the portal).

Good luck

##### Share on other sites

Thank you Andrew. A follow-up question...

It is very likely that I will always start out with "AnyRelatedField" being Null or Empty. How can I make "Null or Empty" sequal ZERO?

For instance right now I'm adding a Payments file that interfaces with my Invoices file. When I create a new invoice, there isn't a payment attached yet, so there are no records in the payments file for that invoice. I have a field in the invoice for Total Remaining which is the ([total due] - [payments received]). Payments Received is a SUM of all the payment amount fields in the portal.

I would like this sum to start out at Zero, but for now it starts out BLANK because there are no related records in the payment file.

Thanks.

##### Share on other sites

First, use a Constant field as you target for the relationship.

Constant(calculation, number, indexed) = 1

Second, format your sum field to show blanks as zero.

-bd

##### Share on other sites

Wes

If the record is related, the match field *must* have a value in it -- it cannot be null or empty because it wouldn't be related to anything if it was.

##### Share on other sites

This topic is 7509 days old. Please don't post here. Open a new topic instead.

## Create an account

Register a new account