# Calculated Fields Explained

**Limited**: Calculated custom fields are only available to certain product editions. [Contact support](https://app.impact.com/support/portal.ihtml?createTicket=true&) to upgrade your advocate program and gain access.

Through [custom fields](https://help.impact.com/brand/advocate-program/manage-advocate-participants/custom-and-calculated-fields/custom-fields-for-advocate-explained), you can send impact.com a wide range of additional information about your Advocate participants beyond the basics required to run your referral program.

Calculated fields receive user and event data, and the values are calculated, stored, and become visible on the participant’s profile. Once the calculated field is set up, its value will update dynamically as you send your Advocate program events that meet your criteria.

{% hint style="info" %}
**Example:** A calculated field can be configured to count how many times a participant makes a purchase of at least $100 in a one-month window. Then, you can set up your program to issue special rewards to participants who make at least 3 of these $100 purchases in a month.
{% endhint %}

#### Default calculated fields

By default, you are supplied with four calculated fields. You can reference these as soon as you start setting up the rules for your program.

<details>

<summary>Default calculated fields</summary>

| Calculated field   | Description                                                                   |
| ------------------ | ----------------------------------------------------------------------------- |
| lastSeenDate       | Tracks the last time the user was upserted in Advocate.                       |
| firstPurchaseDate  | Tracks the first date that we received a purchase event for this participant. |
| lastPurchaseDate   | Tracks the date of the participant’s most recent purchase event.              |
| totalPurchaseCount | Tracks the total number of purchase events for this participant.              |

</details>

#### Client-created calculated fields

You can create your own calculated fields that go beyond the default ones provided. When you set up a calculated field, you can:

* Add a start and end date if you want the calculation to run for a limited time (e.g., January 1st to February 17th). This set time frame is called an active period.
* Specify a recurring [tracking window](https://help.impact.com/brand/advocate-program/manage-advocate-participants/custom-and-calculated-fields/tracking-windows-for-calculated-fields-explained) for your sum and count calculations. Tracking windows can be either fixed windows (e.g., a singular calendar month or year) or sliding windows (e.g., last 90 days).
* Set additional constraints for when the calculation is performed by adding a filter or writing a JSONata expression. These options are discussed in greater detail in our article [Setting Up a Calculated Field](https://help.impact.com/brand/advocate-program/manage-advocate-participants/custom-and-calculated-fields/set-up-a-calculated-field).

{% hint style="info" %}
**Note:** If your calculated field has an active period or tracking window, then values won’t be updated after the calculation period ends. If your calculated field has an active period (or a tracking window, for sum/count calculations only), then values won’t be further updated after the calculation period ends. However, the values will remain visible on each participant’s profile.
{% endhint %}

<details>

<summary>Client-created calculated fields</summary>

There are several types of calculations that you can use when building a calculated field.

| Calculation       | Description                                                                            | Example                                                                                                                                                   |
| ----------------- | -------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Sum               | Calculate the sum of the `{fieldname}` field from `{eventkey}` events                  | Sum all purchases a referred friend makes within the first 30 days after signup. Issue tiered rewards to the customer advocate based on the amount spent. |
| Count             | Count the number of `{eventkey}` events                                                | Reward participants when they have made more than 10 purchases.                                                                                           |
| First Seen (Date) | Calculate the timestamp of the first `{eventkey}` event                                | Reward participants if they started making purchases before a certain date.                                                                               |
| Last Seen (Date)  | Calculate the timestamp of the last `{eventkey}` event                                 | Reward participants if their last purchase was within 5 days.                                                                                             |
| First Value       | Calculate the value of the `{fieldname}` field from the first {eventkey} event         | Reward participants when they make a large first purchase.                                                                                                |
| Last Value        | Calculate the value of the `{fieldname}` field from the most recent `{eventkey}` event | Reward participants when their last payment was at least a certain value.                                                                                 |

</details>
