> ## Documentation Index
> Fetch the complete documentation index at: https://moengage-sdk-deprecated-versions-all-platforms.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Computed Trait

> Walk through the updated MoEngage interface to create computed traits using count, aggregation, first/last value, or SQL-based computations.

<Note>
  This is an Early Access feature. To enable it for your account, please contact your MoEngage Customer Success Manager (CSM) or the Support team.
</Note>

This article guides you through creating a new computed trait, managing existing computations, and using them to enhance your campaigns.

# Create

To get started, perform the following steps:

1. On the sidebar menu in MoEngage, hover over the Data menu item <img alt="data.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/T-f2-X0YLP1-__Vg/images/moengage_0d5b1d.png?fit=max&auto=format&n=T-f2-X0YLP1-__Vg&q=85&s=7e1d7a348af25bf1bf8c3c03f808e4a4" width="44" height="38" data-path="images/moengage_0d5b1d.png" /> . The **Data** menu appears.
2. Click **Computed traits**.
   <img alt="Screenshot 2025-12-10 at 4.37.09 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/xHFYm2acXZLaSsVK/images/moengage_68f477.png?fit=max&auto=format&n=xHFYm2acXZLaSsVK&q=85&s=6cc84912b88bf89ad30d04300fdccd14" width="532" height="292" data-path="images/moengage_68f477.png" />
3. Click **+ Create Computed trait**. The **Create computation** dialog box appears. <img alt="2025-08-18_18-24-47.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/tmJe52I1zwRA1tjR/images/moengage_54ca53.png?fit=max&auto=format&n=tmJe52I1zwRA1tjR&q=85&s=d2a26db8a6a5c596956640c0126b85b9" width="3156" height="936" data-path="images/moengage_54ca53.png" />
4. Click the desired computation method. You have the following options:
   * **Count**
   * **Aggregation**
   * **First/Last Value**
   * **SQL Computation**

For more information on methods of computation and their use cases, refer to [Computed Traits - Overview](/user-guide/data/computed-traits/computed-traits-overview).

The process includes three steps:

* [Step 1: Basic Details](/user-guide/data/computed-traits/create-a-computed-trait)
* [Step 2: Define Computed Trait](/user-guide/data/computed-traits/create-a-computed-trait)
* [Step 3: Scheduling](/user-guide/data/computed-traits/create-a-computed-trait)

## Step 1: Basic Details

First, define the basic details and specify which users the computation applies to.

1. **Computed trait name:** Enter a unique name for your computation. This name will appear as a new user attribute across the MoEngage UI (for example, "Lifetime Value").
2. **Description:** Briefly explain what the computation calculates for your team's reference.
   <img alt="Screenshot 2025-08-18 at 6.42.23 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/4LqsKhrbBZ6pcW3d/images/moengage_2e45e5.png?fit=max&auto=format&n=4LqsKhrbBZ6pcW3d&q=85&s=74f9296c7db4c64d7b64e57b379ad95b" width="3202" height="818" data-path="images/moengage_2e45e5.png" />
3. **Filter users:** Choose the users to be part of the computation. You can select:
   * **All users:** The computation will run for every user in your account.
   * **Filter users by:** Define a specific segment of users based on user properties, events, or affinities. For more information, refer to [Create Segments](/user-guide/segment/segment-operations/rule-based-filter-segments).
     <img alt="Screenshot 2025-08-18 at 6.43.07 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/bMTuAaVW6nJ4NWHm/images/moengage_1e88cd.png?fit=max&auto=format&n=bMTuAaVW6nJ4NWHm&q=85&s=ed7b781e7b498ed9b40962ad8ea6a9d0" width="3188" height="558" data-path="images/moengage_1e88cd.png" />

## Step 2: Define Computed trait

Next, define the logic for how your trait will be calculated.

1. **Select the Type:** In the **Type** section, choose the desired type of computation. You can create traits based on:
   <img alt="Screenshot 2025-08-19 at 1.40.36 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/gEPDUDzN1s3z59r8/images/moengage_be69a6.png?fit=max&auto=format&n=gEPDUDzN1s3z59r8&q=85&s=d1836837e47d9b526f429793a70209c8" width="3174" height="366" data-path="images/moengage_be69a6.png" />
   * **Count:** Count the number of times users performed an action.
   * **Aggregation:** Aggregate values of an event attribute (for example, Total order value).
   * **First/Last Value:** Identify the first or last value of an event attribute.
   * **SQL Computation:** Write a custom SQL query for complex calculations.
2. **Set up the Configuration:** In the **Configuration** section, based on the type of computation that you selected, do the following:
   * For a **Count** computation, select the event to count, define the time period, and optionally add attribute filters.
     <img alt="Screenshot 2025-08-19 at 1.41.45 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/ZOxKy44cenIu0-Tp/images/moengage_15d5f7.png?fit=max&auto=format&n=ZOxKy44cenIu0-Tp&q=85&s=e57eeb969b4cb56d935672867359e4b9" width="3162" height="676" data-path="images/moengage_15d5f7.png" />
   * For an **Aggregation** computation, select the event and the time period. Then, choose the aggregation function. The following functions are available: **Sum, Min, Max, Average, Median, Distinct count,** and **True if event exists**. After selecting the function, select the event attribute you want to compute.
     <img alt="Screenshot 2025-08-19 at 1.49.48 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/f2EcLyVfEkQtCZEh/images/moengage_80819f.png?fit=max&auto=format&n=f2EcLyVfEkQtCZEh&q=85&s=7d94ea4501fe21bfd2c55955375c8197" width="3184" height="772" data-path="images/moengage_80819f.png" />
   * For a **First/Last Value** computation, select the event and time period. Then, choose whether to compute the **First value** or **Last value** of a specific event attribute.
     <img alt="Screenshot 2025-08-19 at 1.51.54 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/5uD-PZQAU3XNefcA/images/moengage_04237f.png?fit=max&auto=format&n=5uD-PZQAU3XNefcA&q=85&s=18088e5f51696b1ed5b49c781a3b96c4" width="3174" height="768" data-path="images/moengage_04237f.png" />
   * For a **SQL Computation**, in the SQL editor, write your query. You can use the left section to browse and select user and event tables. Your query must return two columns: the MoEngage ID and the computed value for your new trait.
     <img alt="Screenshot 2025-08-19 at 2.12.22 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/ErrwfP0EVyD1ze0O/images/moengage_e936f0.png?fit=max&auto=format&n=ErrwfP0EVyD1ze0O&q=85&s=b79180c11cbbefbc6096d29cfed040ca" width="3168" height="1560" data-path="images/moengage_e936f0.png" />
3. **Define the Data type:** Choose the data type of the computed trait's output (for example, **Numerical**, **String**, **Boolean**). Defining a data type is only permitted when you select **SQL** as the computation type. For other computation types, the data type is auto-populated.
4. **Review the Summary:** A plain-language summary of your configuration will be displayed for confirmation.
   <img alt="Screenshot 2025-08-19 at 1.56.12 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/F3GA1hZJh0j2DqI-/images/moengage_4367cb.png?fit=max&auto=format&n=F3GA1hZJh0j2DqI-&q=85&s=dc5dbb526c602169fe3622d8afe0a9ef" width="3152" height="114" data-path="images/moengage_4367cb.png" />
5. **Preview the trait:** Before navigating to the next step, you must test the logic. Perform these steps to preview:
   1. In the **Preview Computed Trait** section, select a preview type.
      * **A specific user**: Test the configuration on a specific user ID.
      * **A set of 10 random users**: Test the configuration on a set of ten random users.
   2. Click **Preview**. A table is generated with ID and computed value.
      <img alt="Screenshot 2025-08-19 at 2.06.47 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/2S_NtlExrHGRF8Ce/images/moengage_58edab.png?fit=max&auto=format&n=2S_NtlExrHGRF8Ce&q=85&s=a789773d13ddc7da4c5e31a2771f0827" width="3168" height="1150" data-path="images/moengage_58edab.png" />
      You can export this preview. To do so, click **Download**.

## Step 3: Scheduling

Finally, decide how and when your computation should run. Perform the following steps to schedule and publish your computed trait.

1. In the **Schedule section**, select when the computation will execute.
   * In the **One-time** section, select **Run at next schedule** to run the computation once at the next scheduled time.\
     or
   * In the **Periodic section**, select the computation to run repeatedly on a **Weekly** or **Monthly** basis to keep the user attribute updated. You can adjust the schedule from the **Settings** page.
     <img alt="Screenshot 2025-08-19 at 2.34.25 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/kSoEJBwjBDxLMVAW/images/moengage_8fd143.png?fit=max&auto=format&n=kSoEJBwjBDxLMVAW&q=85&s=243511d9ea2dff00820c320d70c28cd2" width="3170" height="416" data-path="images/moengage_8fd143.png" />
2. For **Periodic** computations, choose how to handle existing values for users. Select one of the following in the **Computation action**:
   <img alt="Screenshot 2025-08-19 at 2.35.10 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/lXmyQZur-dlbUmK2/images/moengage_df3729.png?fit=max&auto=format&n=lXmyQZur-dlbUmK2&q=85&s=66536813afbaa0cf485eb796d3a663f8" width="3162" height="772" data-path="images/moengage_df3729.png" />
   * **Replace:** Overwrites the old value with the new one for users who meet the computation definition. If a user no longer meets the definition, their existing value is retained.
   * **Compute only for new users:** Calculates the value only for users who do not already have a value for this trait.
   * **Add to existing value:** Adds the newly computed value to the user's current value.
   * **Subtract from existing value:** Subtracts the newly computed value from the user's current value.

Once you are done, click **Publish** to create your computed trait.

# Manage Your Computations

The Computed Traits page lists all the computations you have created.

### Navigation

1. After creating the computed trait, navigate to **Data** > **Computed Traits**. The Computed traits page appears.
   <img alt="Screenshot 2025-08-19 at 2.53.33 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/WBqB1dmopGowKZlW/images/moengage_9a6fa6.png?fit=max&auto=format&n=WBqB1dmopGowKZlW&q=85&s=5af3652334a1baa6327db6bdd4b5f521" width="3134" height="1560" data-path="images/moengage_9a6fa6.png" />
   On this page, you can:
   * Use the search box to search for a computed trait.
   * See information like **Type**, **Schedule**, and **Status**.
   * Use the filters in the header to filter the created computed traits by type, schedule, or status.
2. For a computed trait, you can edit, pause, or view the computation. To do so, click the ellipsis icon against a name and select the desired option.
   <img alt="Screenshot 2025-08-19 at 3.02.47 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/SUHneVVPXn8RBZoX/images/moengage_ac74e0.png?fit=max&auto=format&n=SUHneVVPXn8RBZoX&q=85&s=167900edb726363f8cce8873e001d885" width="3054" height="280" data-path="images/moengage_ac74e0.png" />

* * **View:** See the detailed configuration of a computation on a new page. Alternatively, you can access the detail page by clicking the trait name.
    <img alt="Screenshot 2025-08-19 at 3.20.05 PM.png" src="https://mintcdn.com/moengage-sdk-deprecated-versions-all-platforms/F4AX-8H1I4s7GmM8/images/moengage_c0eeb0.png?fit=max&auto=format&n=F4AX-8H1I4s7GmM8&q=85&s=f4e0f625103b1d534c4c777a4941ae19" width="3154" height="1132" data-path="images/moengage_c0eeb0.png" />
    The detail page contains the following information:
    * **Basic details**: This section contains information on when the computed trait was created, the scheduled details, last run and next run timestamps, and the filtered users' details.
    * **Computation type**: This section contains information about the type of computation and its configuration.
    * **Run history**: This section provides a detailed view of the computation history.
  * **Pause/Resume**: Pause the computation, or resume a paused computation.
  * **Edit:** Modify a computation. You can only make changes before its first scheduled run. After the first run, only the schedule can be changed.

<Info>
  You can have a maximum of five active computations at any given time. This includes computations with **Scheduled**, **Processing**, or **Active** statuses.
</Info>

# Use Your Computed Traits

Once your computation has run successfully, the new trait will be available as a standard user attribute throughout MoEngage.

* **In Segmentation:** In the segment creator, go to **User Property**, find your new computed trait by name, and use it to build your segment.
* **In campaign personalization:** Use Jinja to insert the trait's value directly into your messages. For example: `Hi {{UserAttribute['First Name']}}, you have {{UserAttribute['Loyalty Points']}} points!`. Alternatively, use @ to add the attribute to your content.
* **In Flows:** Use the computed trait as a condition to guide users down different paths in a flow.
