> ## Documentation Index
> Fetch the complete documentation index at: https://docs.zeotap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create a Batch Calculated Attribute

To help you understand the Calculated Attributes better let us consider an example. Assume that you are creating a calculated attribute with the name “`3 months purchase value`”. You are creating this attribute to capture the total cart checkout value for the “`last 3 months`”. In the process, you are going to do a “summation” to aggregate the revenue associated with the “`Order_Completed`” event name. You can further build the condition for the “`Order_Completed`” event name using the values from its mapped Zeotap Catalogue Field. These values can be associated with a product category like brand = Puma.

Now that you have a fair understanding of the sample scenario, perform the following steps to create a calculated attribute:

<Steps>
  <Step>
    Navigate to **Calculated Attributes** under **Unify**.
  </Step>

  <Step>
    Under the **Batch Attributes** tab,
    click + **Create Attribute**.

    <Frame>
      <img src="https://mintcdn.com/zeotap/H0pOTVz_BvaIfSXr/articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/add-a-calculated-attribute-2025-03-05.png?fit=max&auto=format&n=H0pOTVz_BvaIfSXr&q=85&s=2eb9106c986831ef835a765ea9b0cfe3" alt="" width="3526" height="1206" data-path="articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/add-a-calculated-attribute-2025-03-05.png" />
    </Frame>
  </Step>

  <Step>
    In the **Attribute name** field, enter a descriptive name to refer to the calculated attribute.

    <Frame>
      <img src="https://mintcdn.com/zeotap/H0pOTVz_BvaIfSXr/articles/unify-customer/Storage/unify-customer/adding-a-calculated-attribute/adding-a-calculated-attribute-2024-03-11-6.png?fit=max&auto=format&n=H0pOTVz_BvaIfSXr&q=85&s=a776687d4ebb725e9751ea60339da7b6" alt="" width="1742" height="568" data-path="articles/unify-customer/Storage/unify-customer/adding-a-calculated-attribute/adding-a-calculated-attribute-2024-03-11-6.png" />
    </Frame>
  </Step>

  <Step>
    In the **Description** field, enter a description to remember details about the attribute.
  </Step>

  <Step>
    Select the appropriate Aggregation type using the drop-down menu. The values can be `Average`, `Count`, `First Timestamp` and more.

    <Frame>
      <img src="https://mintcdn.com/zeotap/H0pOTVz_BvaIfSXr/articles/unify-customer/Storage/unify-customer/adding-a-calculated-attribute/adding-a-calculated-attribute-2024-03-11-1.png?fit=max&auto=format&n=H0pOTVz_BvaIfSXr&q=85&s=b247e10615822becfc87a3ed534f70da" alt="" width="1366" height="288" data-path="articles/unify-customer/Storage/unify-customer/adding-a-calculated-attribute/adding-a-calculated-attribute-2024-03-11-1.png" />
    </Frame>
  </Step>

  <Step>
    In **Select a field**, choose the attribute on which the calculation works based on the chosen aggregation type. Note that the fields available for Aggregation depends on the type of Aggregation choosen in the first step.
  </Step>

  <Step>
    In **event(s)** field, provide the event names as shown in the image below(Non-mandatory step).

    <Frame>
      <img src="https://mintcdn.com/zeotap/H0pOTVz_BvaIfSXr/articles/unify-customer/Storage/unify-customer/adding-a-calculated-attribute/adding-a-calculated-attribute-2024-03-11-2.png?fit=max&auto=format&n=H0pOTVz_BvaIfSXr&q=85&s=b71713315bd4e02ac1e2bab7530c62e4" alt="" width="1832" height="686" data-path="articles/unify-customer/Storage/unify-customer/adding-a-calculated-attribute/adding-a-calculated-attribute-2024-03-11-2.png" />
    </Frame>
  </Step>

  <Step>
    You can further specify conditions for your Calculated Attributes by clicking **Add Condition**. Note that you can also include [Non-customer entity data](/articles/unify-customer/non-customer-entity-data) in the conditions based on your requirement. 

    <Frame>
      <img src="https://mintcdn.com/zeotap/H0pOTVz_BvaIfSXr/articles/unify-customer/Storage/unify-customer/adding-a-calculated-attribute/adding-a-calculated-attribute-2024-03-11-3.png?fit=max&auto=format&n=H0pOTVz_BvaIfSXr&q=85&s=85fe3d1c4b6a4bd598480e6e85120804" alt="" width="1674" height="674" data-path="articles/unify-customer/Storage/unify-customer/adding-a-calculated-attribute/adding-a-calculated-attribute-2024-03-11-3.png" />
    </Frame>
  </Step>

  <Step>
    In the **Run Computation** section, choose the time period for the calculation.
  </Step>

  <Step>
    In the **Group by** field, select one or more attributes (up to 3) to define how the aggregated values should be grouped. Group by helps you break down one calculated attribute into multiple values.

    **Example**: Instead of calculating a single “3 months purchase value”, you can group it by Product Category to get the total purchase value separately for each category per user.

    Only attributes that are at the same level as the selected aggregation field are shown for Group by.
    For example, if the aggregation is performed on a property inside an object, then only the other properties of that same object (and any joined Non-Customer Entity attributes linked to it) will be available for Group by. Attributes from unrelated objects or levels will not be available.

    <Frame>
      <img src="https://mintcdn.com/zeotap/H0pOTVz_BvaIfSXr/articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/add-a-calculated-attribute-2026-02-02.png?fit=max&auto=format&n=H0pOTVz_BvaIfSXr&q=85&s=75adf8ff768fcb33a290abdb9248c341" alt="" width="1064" height="118" data-path="articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/add-a-calculated-attribute-2026-02-02.png" />
    </Frame>
  </Step>

  <Step>
    Click **Save** to create the Calculated Attribute.
  </Step>
</Steps>

## Create a Calculated Attribute Using the SQL CA Editor

<Note>
  The **SQL CA Editor** is an alternative to the form-based builder. It lets you write the aggregation logic as a SQL query directly, which is useful when the calculation cannot be expressed through the standard form (for example, when you need to filter across different attribute types, combine subqueries, or reference NCE tables). It is available for batch calculated attributes only.
</Note>

<Steps>
  <Step title="Open the create attribute screen">
    Navigate to **Calculated Attributes** under **Unify**, switch to the **Batch Attributes** tab, and click **+ Create Attribute**.
  </Step>

  <Step title="Enter the basic details">
    Fill in the **Attribute name** and **Description** as you would for the form-based flow.
  </Step>

  <Step title="Switch the definition type to SQL">
    On the attribute definition screen, switch the **Definition Type** toggle from **Standard** to **SQL**. The form-based builder is replaced by a SQL query editor.
  </Step>

  <Step title="Write the query">
    Author the aggregation in the editor. The query must follow the validation rules listed in the Help Guide (see the next step). You can reference Zeotap macro tables such as `%%EVENT_STORE%%`, `%%PROFILE_STORE%%`, and others using the `%%MACRO_NAME%%` syntax — Zeotap resolves these to the correct underlying tables for your workspace at runtime.

    <Frame>
      <img src="https://mintcdn.com/zeotap/uGulAA40YNZwfleK/articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/sql-ca-editor-query.png?fit=max&auto=format&n=uGulAA40YNZwfleK&q=85&s=d22b08a0999c713798a1ca22b95c6427" alt="SQL CA Editor with a sample query against the EVENT_STORE macro table" width="1920" height="1080" data-path="articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/sql-ca-editor-query.png" />
    </Frame>
  </Step>

  <Step title="Review the validation rules and supported macro tables">
    Click **Help Guide** to open the SQL Editor reference panel. It documents the validation rules your query must satisfy and the macro tables you can reference.

    <Frame>
      <img src="https://mintcdn.com/zeotap/uGulAA40YNZwfleK/articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/sql-ca-editor-help-guide.png?fit=max&auto=format&n=uGulAA40YNZwfleK&q=85&s=ddf09a6b8ea9a0edac2020c5d321585c" alt="SQL Editor Help Guide showing validation rules and supported macro tables" width="1920" height="1080" data-path="articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/sql-ca-editor-help-guide.png" />
    </Frame>

    **Validation rules**

    * The top-level `SELECT` must return exactly two columns: `ucid` and one aggregated value (with an alias).
    * `ucid` is the only column allowed in the top-level `GROUP BY`.
    * Top-level `LIMIT` and `ORDER BY` are not allowed.
    * CTEs (`WITH` clauses) are not allowed.
    * Subqueries are allowed inside the top-level query.

    **Supported macro tables**

    | Macro                       | Description                                      |
    | --------------------------- | ------------------------------------------------ |
    | `%%ID_STORE%%`              | Identity store for the workspace.                |
    | `%%EVENT_STORE%%`           | Event data store for the workspace.              |
    | `%%PROFILE_STORE%%`         | Profile data store for the workspace.            |
    | `%%CONSENT_STORE%%`         | Consent data store for the workspace.            |
    | `%%NCE_STORE_<SOURCE_ID>%%` | Non-Customer Entity store for a specific source. |
    | `%%ZERO_COPY_<SOURCE_ID>%%` | Zero-copy table for a specific source.           |
  </Step>

  <Step title="Test the query">
    Click **Test Query** to run the query against a sample of your workspace data. The **SQL Test Results** modal shows the first set of rows returned, along with the total result count, so you can confirm the output before saving.

    <Frame>
      <img src="https://mintcdn.com/zeotap/uGulAA40YNZwfleK/articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/sql-ca-editor-test-results.png?fit=max&auto=format&n=uGulAA40YNZwfleK&q=85&s=63f643cf99f7287f92a0890eb0185ff8" alt="SQL Test Results modal showing sample ucid and aggregated value rows" width="1920" height="1080" data-path="articles/unify-customer/Storage/unify-customer/add-a-calculated-attribute/sql-ca-editor-test-results.png" />
    </Frame>

    <Note>
      If the query violates a validation rule (for example, more than two top-level columns or a column other than `ucid` in `GROUP BY`), the test will fail with an error pointing at the offending part of the query.
    </Note>
  </Step>

  <Step title="Save the calculated attribute">
    Once the test query returns the expected results, click **Save** to create the calculated attribute. From this point on it behaves exactly like a form-based batch calculated attribute — it appears on the **Batch Attributes** tab and is available for use in segments and audiences.
  </Step>
</Steps>

## Related Topics

<CardGroup>
  <Card title="Batch Vs. Real Time Calculated Attributes" href="/articles/unify-customer/batch-vs-real-time-calculated-attributes" icon="angles-right" iconType="solid" horizontal={true} />

  <Card title="Components of the Calculated Attributes Screen" href="/articles/unify-customer/components-of-the-calculated-attributes-screen" icon="angles-right" iconType="solid" horizontal={true} />

  <Card title="Create a Real Time Calculated Attribute" href="/articles/unify-customer/create-a-real-time-calculated-attribute" icon="angles-right" iconType="solid" horizontal={true} />

  <Card title="Segment Membership Calculated Attribute" href="/articles/unify-customer/system-defined-calculated-attributes" icon="angles-right" iconType="solid" horizontal={true} />

  <Card title="FAQs about Calculated Attributes" href="/articles/unify-customer/faqs-about-calculated-attributes" icon="angles-right" iconType="solid" horizontal={true} />
</CardGroup>
