

# Set up calculated attributes in Amazon Connect Customer Profiles
<a name="customerprofiles-calculated-attributes"></a>

*Calculated attributes* are values that are derived from other attributes by using formulas. You can use them to identify users' aggregate behaviors.

You can create calculated attributes to define your own business logic to transform your customer profile data into actionable data points. This enables you to personalize automated experiences such as interactive voice responses.

By using calculated attributes, you can identify key attributes about your customer's past behaviour. For example: 
+ The last website visited or last agent spoken to
+ Patterns of behaviour, such as preferred channel and frequency of contact
+ Customer value, such as new customer and average ticket size

You can use the calculated attributes API to create a new attribute using common aggregation operations such as average, count, minimum, maximum, and sum.

Calculated attributes automatically transform raw data in real-time into actionable data points and metrics. Contact center administrators are able to define and configure calculations based on the raw data available in customer profiles. These calculated attributes make it easier for you to build automated experiences such as Interactive Voice Response (IVR) or chatbots. You can build personalized experiences and help agents understand customer context faster.

For a list of AWS Regions where the calculated attributes APIs are available, see [Customer Profiles calculated attributes API availability by Region](regions.md#customerprofiles_calculatedattributesregion). 

**Topics**
+ [Getting started with calculated attributes](customerprofiles-calculated-attributes-admin-website.md)
+ [Calculated attributes APIs](customerprofiles-calculated-attributes-apis.md)
+ [Create a custom calculated attribute definition](customerprofiles-calculated-attributes-creating-definition.md)
+ [Validate calculated attribute values](customerprofiles-calculated-attributes-validating-values.md)
+ [Default calculated attributes](customerprofiles-default-calculated-attributes.md)
+ [Error messages and resolutions](customerprofiles-calculated-attributes-troubleshooting.md)

# Getting started with calculated attributes in Amazon Connect Customer Profiles
<a name="customerprofiles-calculated-attributes-admin-website"></a>

Use calculated attributes to define your own business logic to transform your customer profile data into actionable data points to personalize automated experiences, such as interactive voice responses.

By using calculated attributes, you can identify key attributes about your customer’s past behavior, behavior patterns, and customer value.

The topics in this section show you how to create, view, edit, and delete Calculated Attributes.

**Topics**
+ [Create calculated attributes](calculated-attributes-admin-website-create.md)
+ [Set up event filters](calculated-attributes-admin-website-event-filters.md)
+ [View calculated attributes](calculated-attributes-admin-website-view.md)
+ [Edit calculated attributes](calculated-attributes-admin-website-edit.md)
+ [Delete calculated attributes](calculated-attributes-admin-website-delete.md)

# Create calculated attributes in Amazon Connect
<a name="calculated-attributes-admin-website-create"></a>

1. Prerequisites: Ensure you have the necessary security profile permissions. For more information, see [Update permissions for calculated attributes in Amazon Connect Customer Profiles](security-profile-customer-profile-calc-attribs.md).

1. In Amazon Connect admin website, navigate to **Customer Profiles**, **Calculated attributes**, choose **Create attribute** in the **Calculated attributes** table view.  
![\[The Customer profiles tab in the agent workspace, the Associate button.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-create-1.png)

1. To create a calculated attribute, assign a descriptive name, add description (optional) with details about the attribute, and configure the required fields:
   + **Calculation:** Defines how attributes are computed (average/count/sum/minimum/first occurrence/last occurrence/max occurrence).
   + **Attribute:** A data point from your customer profiles data.
**Note**  
If you are selecting an attribute from a standard object type (`_asset`, `_case`, `_order`), the attributes must be in PascalCase. This means that the first letter of each word in the attribute name is capitalized, such as `_case.CreatedBy` or `_order.TotalPrice`.  
![\[The Customer profiles tab in the agent workspace, the Associate button.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-create-2.png)

1. Additionally, you can add another attribute by selecting the *plus* icon. You can choose up to two attributes to calculate and combine them by an operator. Specify an operator such as *plus* or *minus* to combine the attribute values.  
![\[The Customer profiles tab in the agent workspace, the Associate button.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-create-3.png)

1. Once the calculation is selected, you can optionally configure the Number of events, Time period, and Source timestamp. By default, calculated attributes is configured to use unlimited events, an unlimited time period, and a timestamp based on ingestion date.

   An output is returned when there is at least one event during the specified time period.
   + **Number of events:** configure limit or use unlimited (default)
   + **Time period:** set specific timeframe or use unlimited (default)
   + **Source timestamp:** choose between a specific timestamp field or ingestion date (default)
**Note**  
While there's no event limit, a data size limit exists where oldest data will be replaced by newer data. Source timestamp cannot be changed after creation.  
![\[The Customer profiles tab in the agent workspace, the Associate button.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-create-4.png)

1. Optionally, you can define criteria to include only relevant events in calculations. See [Set up event filters](calculated-attributes-admin-website-event-filters.md) for more information.

1. Select **Create** to create the calculated attribute.

1. After a calculated attribute has been created successfully, a banner is displayed on the table view for using the calculated attribute in a segment or flow. You will also be able to view the status of calculated attributes based on the readiness.  
![\[A banner that the calculated attribute has been created.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-create-5.png)

# Set up event filters
<a name="calculated-attributes-admin-website-event-filters"></a>

Event filters allow you to filter the profile objects to be used in the calculated attribute. For example, an event filter might filter the customer's standard asset objects so that only the assets with **Status is Installed OR Registered** are included in the calculation.

**Note**  
You cannot edit event filters after creating a calculated attribute definition.

When you create a calculated attribute, you can create one or more event filters. An event filter consists of the following components:

![\[Event filter components.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-event-filters-1.png)

+  **Filter groups**: Group of filters that you apply to the profile objects. You can add multiple filter groups which are connected by OR relationships. 
+  **Filters**: Filters the profile objects that are included in the calculation of the calculated attribute by specifying attributes, operators, and values. You can add as many filters as needed for your use case. 
+  **Attribute**: The attribute of the object to filter by. You can select attributes from objects stored in the Customer Profiles domain or use the field names defined in the object type definition. for more information about object type mappings, see [Object type mapping definition details in Amazon Connect Customer Profiles](object-type-mapping-definition-details.md).
**Note**  
 In Amazon Connect admin website, the attribute dropdown shows the timestamp of the last time any profile object was saved or updated with the attribute. 
 If there is both an attribute of a profile object and a field of an object type with the same name, the event filter prioritizes the object type field name in its filtering. For example, if a profile object has an attribute named **Status** and there is also an object type field named **Status**, the filter will use the object type field **Status** for filtering. 
+  **Operator** — The operator determines the relationship of the attribute to a value you enter. For more information, see [Filter operators](#calculated-attributes-admin-website-event-filter-operators)
+  **Value** — The value to filter objects with. You can specify multiple values connected by OR relationships. For example, *Asset's Status is Installed or Registered*. Note that values are case-sensitive. For example, *Asset's Status is Installed* returns different results than *Asset's Status is installed*. To view profile objects, use the Amazon Connect Customer Profiles [ListProfileObjects](https://docs.aws.amazon.com/connect/latest/APIReference/API_connect-customer-profiles_ListProfileObjects.html) API.

 You can optionally create up to two event filters and create a relationship (AND/OR/EXCLUDE) between them. For more details about the relationship, see [Relationship between event filters](#calculated-attributes-admin-website-relationship-between-event-filters). 

 

## Filter operators
<a name="calculated-attributes-admin-website-event-filter-operators"></a>

Operators determine the relationship of the attribute to a value you enter. The following table describes the available operators.

[\[See the AWS documentation website for more details\]](http://docs.aws.amazon.com/connect/latest/adminguide/calculated-attributes-admin-website-event-filters.html)

**Note**  
 Calculated attributes in the Amazon Connect admin website use the UTC timezone and a default time of 00:00:00 UTC for all time-based filters. You can filter on dates but times are recorded as the same value. If you enter a date of 2024-01-01, the console passes the time as 2024-01-01T00:00:00Z. 

**Note**  
By default, event filters are evaluated when a profile object is saved or updated. For instance, if you filter standard asset objects where the `PurchaseDate` is within the last week, the relative time is calculated as *within the last week from the moment the asset object is saved or updated*. This means the filtering results may vary depending on when the object is saved or updated.

## Relationship between event filters
<a name="calculated-attributes-admin-website-relationship-between-event-filters"></a>

 Optionally, you can add the second event filter and define a relationship with the first event filter. When you create a calculated attribute in the Amazon Connect admin website, you can have a maximum of two event filters per calculated attribute. If you add the second event filter to your calculated attribute, you can choose one of two ways to specify how the two event filters are connected: 
+  **AND relationship** — If you use the AND relationship to connect two event filters, objects that meets both the first and second event filter, will be included in the calculation. 
+  **OR relationship** — If you use the OR relationship to connect two event filters, objects that meets either the first or second event filter, will be included in the calculation. 
+  **EXCLUDE relationship** — If you use the EXCLUDE relationship to connect two event filters, objects that meets the first event filter but does not meet the second event filter, will be included in the calculation. 

## Next steps
<a name="calculated-attributes-admin-website-event-filter-next-steps"></a>
+  [Use your calculated attribute in your contact center via the Flow editor](https://docs.aws.amazon.com/connect/latest/adminguide/customer-profiles-block.html#customer-profiles-block-properties-get-calculated-attributes) 
+  [Use your calculated attribute to define a customer segment](https://docs.aws.amazon.com/connect/latest/adminguide/segmentation-admin-website)
+  [View Calculated Attributes in Amazon Connect](https://docs.aws.amazon.com/connect/latest/adminguide/calculated-attributes-admin-website-view.html) 
+  [Edit Calculated Attributes in Amazon Connect](https://docs.aws.amazon.com/connect/latest/adminguide/calculated-attributes-admin-website-edit.html) 
+  [Delete Calculated Attributes in Amazon Connect](https://docs.aws.amazon.com/connect/latest/adminguide/calculated-attributes-admin-website-delete.html) 

# View calculated attributes in Amazon Connect
<a name="calculated-attributes-admin-website-view"></a>

1. Log in to the Amazon Connect admin website at https://*instance name*.my.connect.aws/. Use an Admin account, or an account assigned to a security profile that has **Customer Profiles - Calculated Attributes** permission. permission. 

1. In Amazon Connect, on the left navigation pane, choose **Customer Profiles**, **Calculated attributes**.

1. On the **Calculated attributes** page, choose a calculated attribute from the **Name** column in the table. 

   The following image shows an example of calculated attributes listed in the **Name** column.  
![\[A table that lists calculated attributes.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-view-1.png)

1. You can now view the details of the attribute that you selected. The following image shows a page of details for a calculated attribute.  
![\[Detailed view of a calculated attribute.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-view-2.png)

# Edit calculated attributes in Amazon Connect
<a name="calculated-attributes-admin-website-edit"></a>

1. To edit a calculated attribute, choose an attribute in the table view by selecting the radio button, which enables the **Edit** button. Choose **Edit**.  
![\[edit a calculated attribute\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-edit-1.png)

1. You can edit the **Description**, **Number of events**, and **Time period**. When done, choose **Save**.  
![\[Edit a calculated attribute.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-edit-2.png)

# Delete calculated attributes in Amazon Connect
<a name="calculated-attributes-admin-website-delete"></a>

1. To delete a calculated attribute, choose an attribute in the table by selecting the radio button next to the attribute that you would like to delete.

1. Once selected, choose **Delete**.

1. In the **Delete Attribute** pop-up, verify the details and enter *confirm* to enable the **Delete** button.  
![\[Delete a calculated attribute.\]](http://docs.aws.amazon.com/connect/latest/adminguide/images/calculated-attributes-admin-website-delete-1.png)

1. Choose **Delete**.

# Amazon Connect Customer Profiles calculated attributes APIs
<a name="customerprofiles-calculated-attributes-apis"></a>

You can use the following Customer Profiles calculated attribute APIs

------
#### [ CreateCalculatedAttributeDefinition ]

**CreateCalculatedAttributeDefinition**

Create a new calculated attribute. This requires an existing object type in the domain. You can define attributes that you want to pull from a single source object and the mathematical operations to apply to them in aggregate as well as the time range and object count.

After creation, new object data ingested into Customer Profiles will be included in the calculated attribute, which can be retrieved for a profile using the `GetCalculatedAttributeForProfile` API. To use historical data as well, specify `UseHistoricalData` as true. The `Readiness` and `Status` fields on the API response will provide information regarding the status of including historical data in the calculated attribute. 

Defining a calculated attribute makes it available for all profiles within a domain. Each calculated attribute can only reference one ObjectType and at most two fields from that ObjectType.

**Request**

```
POST /domains/DomainName/calculated-attributes/CalculatedAttributeName
```

```
{
    "CalculatedAttributeName": "string",
    "DisplayName": "string",
    "Description": "string",
    "AttributeDetails": {
       "Attributes": [
           {
               "Name": "string"
           }
           ...
       ],
       "Expression": "string",
    },
    "Statistic": "AVERAGE" | "COUNT" | "SUM" | "FIRST_OCCURRENCE" | "LAST_OCCURRENCE" | "MINIMUM" | "MAXIMUM" | "MAX_OCCURRENCE",
    "Conditions": {
        "Range": {
             "Value": "number",
             "Units": "string"
        },
        "ObjectCount": "number",
        "Threshold": {
            "Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
     },
     "Tags": {}
}
```

**Response**

```
{
    "CalculatedAttributeName": "string",
    "DisplayName": "string",
    "Description": "string",
    "AttributeDetails": {
       "Attributes": [
           {
               "Name": "string"
           }
           ...
       ],
       "Expression": "string",
    },
    "Statistic": "AVERAGE" | "COUNT" | "SUM" | "FIRST_OCCURRENCE" | "LAST_OCCURRENCE" | "MINIMUM" | "MAXIMUM" | "MAX_OCCURRENCE"
    "Conditions": {
        "Range": {
             "Value": "number",
             "Units": "string"
        },
        "ObjectCount": "number",
        "Threshold": {
            "Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
    },
    "CreatedAt": number,
    "LastUpdatedAt": number,
    "Tags": {}
}
```

**Request body**
+ **CalculatedAttributeName**

  The unique (per domain) name of the calculated attribute.
  + Type : String
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z0-9_-]+$`
  + Required: Yes
+ **DisplayName**

  The display name of the calculated attribute.
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z_][a-zA-Z_0-9-\s]*$`
  + Required: No
+ **Description**

  The description of the calculated attribute.
  + Type : String
  + Length Constraints: Minimum length of 1. Maximum length of 1000.
  + Required: No
+ **UseHistoricalData**

  Whether historical data ingested before the Calculated Attribute was created should be included in calculations.
  + Type : Boolean
  + Required: No
+ **AttributeDetails**

  Details of the attributes used in the definition and the mathematical operations involved between the attributes. See the following components:
  + **Attributes**

    A list of attribute items specified in the mathematical expression.
    + **AttributeItem**

      The details of a single attribute item specified in the mathematical expression.
      + Name
        + The name of an attribute defined in a profile object type.
        + Type: String
  + **Expression**

    Mathematical expression that is performed on attribute items provided in the attribute list. Each element in the expression should follow the structure of \$1"\$1ObjectTypeName.AttributeName\$1\$1".
    + Example : `{ObjA.AttributeA} - {ObjA.AttributeB}`
    + Type : String
    + We only support the following mathematical operations: `+ - * /`
    + You cannot make modifications to the Expression once a calculated attribute definition is created
+ **Conditions**

  Defines the calculated attribute aggregation criteria and threshold.
  + Type: Conditions object
    + Range
    + ObjectCount
    + Threshold
+ **Range**

  The relative time period over which data is included in the aggregation.
  + Type: Range object
    + Value: The length of time of the specified units. `ValueRange` overrides Value.
      + Type: Integer
      + Required: No
    + ValueRange: A structure letting customers specify a relative time window over which over which data is included in the Calculated Attribute. Use positive numbers to indicate that the endpoint is in the past, and negative numbers to indicate it is in the future. ValueRange overrides Value.
      + Type: ValueRange
      + Required: No
        + Start
          + The start time of when to include objects. Use positive numbers to indicate that the startpoint is in the past, and negative numbers to indicate it is in the future.
          + Type: Integer
          + Required: Yes 
        + End
          + The end time of when to include objects. Use positive numbers to indicate that the startpoint is in the past, and negative numbers to indicate it is in the future.
          + Type: Integer
          + Required: Yes 
    + TimestampSource: An expression specifying the field in your JSON object from which the date should be parsed. The expression should follow the structure of \$1"\$1ObjectTypeName.<Location of timestamp field in JSON pointer format>\$1\$1". For example, if your object type is MyType and source JSON is `{"generatedAt": {"timestamp": "1737587945945"}}`, then TimestampSource should be `"{MyType.generatedAt.timestamp}"`.
      + Length Constraints: Minimum length of 1. Maximum length of 255.
      + Required: No
    + TimestampFormat: The format the timestamp field in your JSON object is specified. This value should be one of EPOCHMILLI (for Unix epoch timestamps with second/millisecond level precision) or ISO\$18601 (following ISO\$18601 format with second/millisecond level precision, with an optional offset of Z or in the format HH:MM or HHMM.). For example, if your object type is MyType and source JSON is `{"generatedAt": {"timestamp": "2001-07-04T12:08:56.235-0700"}},` then TimestampFormat should be `"ISO_8601"`.
    + Unit: Unit of time
      + Valid values: Days
      + Required: Yes
  + Required: Yes
  + Initial scope: Max of 366 days
+ **ObjectCount**

  The number of profile objects used for the calculated attribute.
  + Type: Number
  + Range: 1 through 100
  + Required: No
+ **Threshold**

  The comparison logic to generate a true/false calculated attribute.
  + Type: Threshold object
    + Value
      + The value of the threshold
      + Type: String
      + Required: No
    + Operator
      + The operator of the threshold
      + Type: ENUM
      + Valid Values:
        + GREATER\$1THAN
        + LESS\$1THAN
        + EQUAL\$1TO
        + NOT\$1EQUAL\$1TO
  + Required: No
+ **Statistic**

  The aggregation operation to perform for the calculated attribute.
  + Type: ENUM
  + Valid Values:
    + FIRST\$1OCCURRENCE
    + LAST\$1OCCURRENCE
    + COUNT
    + SUM
    + MINIMUM
    + MAXIMUM
    + AVERAGE
    + MAX\$1OCCURRENCE

------
#### [ UpdateCalculatedAttributeDefinition ]

**UpdateCalculatedAttributeDefinition**

Update a calculated attribute definition. Updates are limited to display name, description, time range, object count, and threshold. This API supports partial updates, so only the parameters that require updating need to be included.

**Note**  
When updating the Conditions:  
Increasing the date range of a calculated attribute will not trigger inclusion of historical data greater than the current date range.
TimestampSource and TimestampFormat cannot be updated after a calculated attribute definition has been created.

**Request**

```
PUT /domains/DomainName/calculated-attributes/CalculatedAttributeName
```

```
{
    "DisplayName": "string",
    "Description": "string",
    "Conditions": {
        "Range": {
             "Value": "number",
             "Units": "string"
        },
        "ObjectCount": "number",
        "Threshold": {
            "Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
   }
}
```

**Response**

```
{
    "CalculatedAttributeName": "string",
    "DisplayName": "string",
    "Description": "string",
    "AttributeDetails": {
       "Attributes": [
           {
               "Name": "string"
           }
           ...
       ],
       "Expression": "string",
    },
    "Statistic": "AVERAGE" | "COUNT" | "SUM" | "FIRST_OCCURRENCE" | "LAST_OCCURRENCE" | "MINIMUM" | "MAXIMUM" | "MAX_OCCURRENCE"
    "Conditions": {
        "Range": {
             "Value": "number",
             "Units": "string"
        },
        "ObjectCount": "number",
        "Threshold": {
            "Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
    },
    "CreatedAt": number,
    "LastUpdatedAt": number,
    "Tags": {}
}
```

**Request body**
+ **DisplayName**

  The display name of the calculated attribute.
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z_][a-zA-Z_0-9-\s]*$`
  + Required: No
+ **Description**

  The description of the calculated attribute.
  + Type : String
  + Length Constraints: Minimum length of 1. Maximum length of 1000.
  + Required: No
+ **Conditions**

  Defines the calculated attribute aggregation criteria and threshold.
  + Type: Conditions object
    + Range
    + ObjectCount
    + Threshold
+ **Range**

  The relative time period over which data is included in the aggregation.
  + Type: Range object
    + Value: The length of time of the specified units
      + Type: Integer
      + Required: No
    + ValueRange: A structure letting customers specify a relative time window over which over which data is included in the Calculated Attribute. Use positive numbers to indicate that the endpoint is in the past, and negative numbers to indicate it is in the future. ValueRange overrides Value.
      + Type: ValueRange
      + Required: No
        + Start
          + The start time of when to include objects. Use positive numbers to indicate that the startpoint is in the past, and negative numbers to indicate it is in the future.
          + Type: Integer
          + Required: Yes 
        + End
          + The end time of when to include objects. Use positive numbers to indicate that the startpoint is in the past, and negative numbers to indicate it is in the future.
          + Type: Integer
          + Required: Yes 
    + Unit: Unit of time
      + Valid values: Days
      + Required: Yes
  + Required: Yes
  + Initial scope: Max of 366 days
+ **ObjectCount**

  The number of profile objects used for the calculated attribute.
  + Type: Number
  + Range: 1 through 100
  + Required: No
+ **Threshold**

  The comparison logic to generate a true/false calculated attribute.
  + Type: Threshold object
    + Value
      + The value of the threshold
      + Type: String
      + Required: No
    + Operator
      + The operator of the threshold
      + Type: ENUM
      + Valid Values:
        + GREATER\$1THAN
        + LESS\$1THAN
        + EQUAL\$1TO
        + NOT\$1EQUAL\$1TO
  + Required: No

------
#### [ GetCalculatedAttributeDefinition ]

**GetCalculatedAttributeDefinition**

Retrieve a calculated attribute definition.

**Request**

```
GET /domains/DomainName/calculated-attributes/CalculatedAttributeName
```

**Request Body**

```
The request does not have a request body.
```

**Response**

```
{
"CalculatedAttributeName": "string",
    "DisplayName": "string",
    "Description": "string",
    "AttributeDetails": {
"Attributes": [
           {
"Name": "string"
           }
           ...
       ],
       "Expression": "string",
    },
    "Statistic": "AVERAGE" | "COUNT" | "SUM" | "FIRST_OCCURRENCE" | "LAST_OCCURRENCE" | "MINIMUM" | "MAXIMUM" | "MAX_OCCURRENCE"
"Conditions": {
"Range": {
      "Unit": "string",
      "Value": number
      "ValueRange"
        {
            "Start": number 
            "End": number 
        },
      "TimestampFormat": "string", 
      "TimestampSource": "string"
    },
        "ObjectCount": "number",
        "Threshold": {
"Value": "string",
            "Operator": "EQUAL_TO" | "GREATER_THAN" | "LESS_THAN" | "NOT_EQUAL_TO"
        }
    },
    "UseHistoricalData" boolean,
  "Status": "PREPARING" | "IN_PROGRESS" | "COMPLETED" | "FAILED",
  "Readiness": {
        "ProgressPercentage": number, 
        "Message": "string", 
        },
    "CreatedAt": number,
    "LastUpdatedAt": number,
    "Tags": {}
}
```

**URI request parameters**
+ **DomainName**

  The unique name of the domain.
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z0-9_-]+$`
  + Required: Yes
+ **CalculatedAttributeName**

  The unique (per domain) name of the calculated attribute.
  + Type : String
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z0-9_-]+$`
  + Required: Yes

------
#### [ DeleteCalculatedAttributeDefinition ]

**DeleteCalculatedAttributeDefinition**

Delete an existing calculated attribute definition. Note that deleting a default calculated attribute is possible, however once deleted you will be unable to undo that action and will need to recreate it on your own using the `CreateCalculatedAttributeDefinition` API if you want it back.

**Request**

```
DELETE /domains/DomainName/calculated-attributes/CalculatedAttributeName
```

**Request Body**

```
The request does not have a request body.
```

**Response**

```
The response does not have a response body.
```

**URI request parameters**
+ **DomainName**

  The unique name of the domain.
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z0-9_-]+$`
  + Required: Yes
+ **CalculatedAttributeName**

  The unique (per domain) name of the calculated attribute.
  + Type : String
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z0-9_-]+$`
  + Required: Yes

------
#### [ ListCalculatedAttributeDefinitions ]

**ListCalculatedAttributeDefinitions**

Retrieve all calculated attribute definitions for a domain.

**Request**

```
GET /domains/DomainName/calculated-attributes?max-results=MaxResults&next-token=NextToken
```

**Request Body**

```
The request does not have a request body.
```

**Response**

```
{ 
    "Items": [
        {
            "UseHistoricalData": boolean,
            "ReadinessStatus": PREPARING | IN_PROGRESS | COMPLETED | FAILED,
            "CalculatedAttributeName": "string", 
            "CreatedAt": number, 
            "Description": "string", 
            "DisplayName": "string", 
            "LastUpdatedAt": number, 
            "Tags": { 
                "string" : "string" 
            }
        } 
    ], 
    "NextToken": "string"
}
```

**URI request parameters**
+ **DomainName**

  The unique name of the domain.
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z0-9_-]+$`
  + Required: Yes
+ **MaxResults**

  The maximum number of objects returned per page.
  + Valid Range: Minimum value of 1. Maximum value of 100
+ **NextToken**

  The pagination token from the previous ListCalculatedAttributeDefinition API call.
  + Length Constraints: Minimum length of 1. Maximum length of 1024

------
#### [ GetCalculatedAttributeForProfile ]

**GetCalculatedAttributeForProfile**

Initiates the calculation and retrieves the result of a single calculated attribute for a single profile.

**Request**

```
GET /domains/DomainName/profile/ProfileId/calculated-attributes/CalculatedAttributeName
```

**Request Body**

```
The request does not have a request body.
```

**Response**

```
{
"Name": "string",
    "DisplayName": "string",
    "Value": "string",
    "IsDataPartial": "string",
    "LastObjectTimestamp" : number
}
```

**URI request parameters**
+ **DomainName**

  The unique name of the domain.
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z0-9_-]+$`
  + Required: Yes
+ **CalculatedAttributeName**

  The unique (per domain) name of the calculated attribute.
  + Type : String
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z0-9_-]+$`
  + Required: Yes

------
#### [ ListCalculatedAttributesForProfile ]

**ListCalculatedAttributesForProfile**

Initiates the calculation and retrieves the results of all calculated attributes for a single profile.

**Request**

```
GET /domains/DomainName/profile/ProfileId/calculated-attributes?max-results=MaxResults&next-token=NextToken
```

**Request Body**

```
The request does not have a request body.
```

**Response**

```
{
"Items": [
        {
"CalculatedAttributeName": "string",
            "DisplayName": "string",
            "Value": "string",
            "IsDataPartial" : "string",
            "LastObjectTimestamp" : number
        },
        ...
    ],
    "NextToken": "string"
}
```

**URI request parameters**
+ **DomainName**

  The unique name of the domain.
  + Length Constraints: Minimum length of 1. Maximum length of 64.
  + Pattern: `^[a-zA-Z0-9_-]+$`
  + Required: Yes
+ **ProfileId**
  + Pattern: `[a-f0-9]{32}`
  + Required: Yes
+ **MaxResults**

  The maximum number of objects returned per page.
  + Valid Range: Minimum value of 1. Maximum value of 100
+ **NextToken**

  The pagination token from the previous ListCalculatedAttributeDefinition API call.
  + Length Constraints: Minimum length of 1. Maximum length of 1024

------

# Create a custom Amazon Connect Customer Profiles calculated attribute definition
<a name="customerprofiles-calculated-attributes-creating-definition"></a>

Using the Customer Profiles [CreateCalculatedAttributeDefinition](https://docs.aws.amazon.com/customerprofiles/latest/APIReference/API_CreateCalculatedAttributeDefinition.html) API, you can programmatically create your own calculated attribute based on a custom object type.

In this topic we show how to create a calculated attribute using a custom JSON file.

## Step 1: Create a JSON file
<a name="step1-calculate-attribute-api"></a>

Create a JSON file with the following contents:

```
{
"DomainName": "your-domain-name", 
   "CalculatedAttributeName": "your-calculated-attribute-name",
   "UseHistoricalData": true,
   "DisplayName": "your-display-name",
   "Description": "your-description",
   "AttributeDetails": {
"Attributes": [
         {
            "Name": "your-attribute-name"
         }
       ],
       "Expression": "{your-object-type.your-attribute-name}"
   },
    "Statistic": "your-statistic",
    "Conditions": {
       "Range": {
        "ValueRange"
        {
            "Start": your-range-start
            "End": your-range-end
        },
        "TimestampSource": "{your-object-type.your-timestamp-source}",          
        "Unit": "days"
        },
        "ObjectCount":  your-object-count,
        "Threshold": {
           "Value": "your-threshold-value",
           "Operator": "your-threshold-operator"
        }
   }  
}
```

To customize the JSON with your own values, follow these guidelines:
+ **Attributes**: This should contain the name of the field from your object type that you want to use for the calculated attribute. Two attributes being referenced in this list are supported.
+ **Expression**: Basic math expressions to perform between attributes are supported. If you only have one attribute, this field should be `{ObjectTypeName.AttributeName}`, otherwise if you have a math expression in mind this field should contain both attributes.
+ **Statistic**: This is the operation performed when you call one of the calculate APIs that actually performs the aggregation operation. Most are self-explanatory, but we have added explanations for ones that aren’t. 

  **Supported statistics**
  + `FIRST_OCCURRENCE` returns the attribute specified in the expression of the earliest ingested object.
  + `LAST_OCCURRENCE` returns the attribute specified in the expression of the latest ingested object.
  + `COUNT` returns the count from the selected data.
  + `SUM` returns the sum from the selected data.
  + `MINIMUM` returns minimum from the selected data.
  + `MAXIMUM` returns maximum from the selected data.
  + `AVERAGE` returns average from the selected data.
  + `MAX_OCCURRENCE` returns the most frequently occurring value specified in the expression.
+ **Range**:
  + Units: Currently supports only DAYS units.
  + ValueRange: Specify positive numbers in ValueRange’s Start or End fields to indicate how many days ago to begin from, and negative numbers to indicate how many days in the future to begin from.
  + TimestampSource: An expression specifying the field in your JSON object from which the date should be parsed. The expression should follow the structure of \$1"\$1ObjectTypeName.<Location of timestamp field in JSON pointer format>\$1\$1". For example; if your object type is MyType and source JSON is `{"generatedAt": {"timestamp": "1737587945945"}}`, then TimestampSource should be `"{MyType.generatedAt.timestamp}"`.
+ **ObjectCount**: Indicates how many objects the calculated attribute calculation should be based on.
+ **Threshold**: If instead of the exact calculated attribute value you instead want to know if it’s, for example, greater than a certain value, you can use a threshold.

  The threshold value can be any string, and the following threshold operators are supported.
  + `GREATER_THAN`
  + `LESS_THAN`
  + `EQUAL_TO`
  + `NOT_EQUAL_TO`
+ UseHistoricalData: Whether historical data ingested before the Calculated Attribute was created should be included in calculations.

## Step 2: Call the CreateCalculatedAttributeDefinition API
<a name="step2-calculated-attribute-api"></a>

After you have created and customized the JSON file with your values, call the [CreateCalculatedAttributeDefinition](https://docs.aws.amazon.com/customerprofiles/latest/APIReference/API_CreateCalculatedAttributeDefinition.html) API, as shown in the following example:

```
aws customer-profiles create-calculated-attribute-definition --cli-input-json file:///custom_calculated_attribute_cli.json --region region_name
```

You can also use the following endpoint:

```
https://profile.your-region.amazonaws.com/domains/your-domain-name/calculated-attributes
```

# Validate calculated attribute values in Amazon Connect Customer Profiles using APIs
<a name="customerprofiles-calculated-attributes-validating-values"></a>

There are two APIs, `GetCalculatedAttributeForProfile` and `ListCalculatedAttributesForProfile`, that are at the profile level.
+ **GetCalculatedAttributeForProfile** - retrieves a single calculated attribute for a single profile.
+ **ListCalculatedAttributesForProfile** - retrieves a list of calculated attributes for a single profile

With a valid profile ID, you should see values for your calculated attributes:

**Example response**

```
{   
    "CalculatedAttributeName": "_average_hold_time",
    "DisplayName": "Average hold time",
    "IsDataPartial": "true",
    "Value": "24144"
}
```

**IsDataPartial** - This flag means that either the time range (30 days) or object count have not been achieved and therefore the calculated attribute is still being calculated. For example, if you want an average over 30 days, only after 30 days have elapsed will the `IsDataPartial` field be set to false.

## Retrieve a list of calculated attributes
<a name="calculated-attributes-validating-a-list-of-values"></a>

**Use the AWS CLI**

```
aws customer-profiles list-calculated-attributes-for-profile --region your-region --domain-name your-domain-name --profile-id your-profile-id
```

**Use the AWS CLI with a custom JSON file**

Create a JSON file with the following contents:

```
{
    "DomainName": "your-domain-name", 
    "ProfileId" "some-profile-id"
}
```

```
aws customer-profiles list-calculated-attributes-for-profile --region your-region --cli-input-json file://list_calculated_attributes_for_profile_cli.json
```

**Endpoint:**

```
https://profile.your-region.amazonaws.com/domains/your-domain-name/profile/your-profile-id/calculated-attributes/
```

## Retrieve a single calculated attribute
<a name="calculated-attributes-validating-a-single-value"></a>

**Use the AWS CLI**:

```
aws customer-profiles get-calculated-attributes-for-profile --region your-region --domain-name your-domain-name --calculated-attribute-name your-calculated-attribute-name --profile-id your-profile-id
```

**Use the AWS CLI with a custom JSON file**:

Create a JSON file with the following contents:

```
{   
    "DomainName": "your-domain-name", 
    "CalculatedAttributeName": "your-calculated-attribute-name",
    "ProfileId" "your-profile-id"
}
```

```
aws customer-profiles get-calculated-attributes-for-profile --region your-region --cli-input-json file://list_calculated_attributes_for_profile_cli.json
```

**Endpoint:**

```
https://profile.your-region.amazonaws.com/domains/your-domain-name/profile/your-profile-id/calculated-attributes/your-calculated-attribute-name
```

# Default calculated attributes in Amazon Connect Customer Profiles
<a name="customerprofiles-default-calculated-attributes"></a>

## Default CTR calculated attributes
<a name="customerprofiles-default-calculated-attributes-ctr"></a>

Amazon Connect Customer Profiles provides out-of-the box default attributes based on contact records. The attributes are as follows:

**Most frequent channel**

```
{
   "CalculatedAttributeName": "_most_frequent_channel",
   "DisplayName": "Most frequent channel",
   "Description": "Returns customer's frequently used communication channel. Channels include voice, chat, task.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "MAX_OCCURRENCE",
   "Conditions": {
      "Range": {
         "Value": 30,
         "Unit": "DAYS"
       },
       "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "channel"
         }
      ],
      "Expression": "{CTR.channel}"
   },
   "Tags": {
   }
}
```

**Last channel**

```
{
   "CalculatedAttributeName": "_last_channel",
   "DisplayName": "Last channel",
   "Description": "Returns customer's last communication channel. Channels include voice, chat, task.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "LAST_OCCURRENCE",
   "Conditions": {
      "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "channel"
         }
       ],
       "Expression": "{CTR.channel}"
   },
   "Tags": {
   }
}
```

**Last agent identifier**

```
{
   "CalculatedAttributeName": "_last_agent_id",
   "DisplayName": "Last agent identifier",
   "Description": "Returns identifier of the last agent customer connected with.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "LAST_OCCURRENCE",
   "Conditions": {
      "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "agent.id"
         }
      ],
      "Expression": "{CTR.agent.id}"
   },
   "Tags": {
   }
}
```

**Frequent caller**

```
{
   "CalculatedAttributeName": "_frequent_caller",
   "DisplayName": "Frequent caller",
   "Description": "Returns true or false based on the number of times a customer has called.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "COUNT",
   "Conditions": {
      "Range": {
         "Value": 30,
         "Unit": "DAYS"
      },
      "ObjectCount": null,
      "Threshold": {
         "Value": "5",
         "Operator": "GREATER_THAN"
      }
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "contactId"
         }
      ],
      "Expression": "{CTR.contactId}"
   },
   "Tags": {
   }
}
```

**Average hold time**

```
{
   "CalculatedAttributeName": "_average_hold_time",
   "DisplayName": "Average hold time",
   "Description": "Returns customer's average hold time for voice calls.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "AVERAGE",
   "Conditions": {
      "Range": {
         "Value": 30,
         "Unit": "DAYS"
      },
      "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "agent.customerHoldDurationMillis"
         },
         {
            "Name": "queue.durationMillis"
         }
      ],
      "Expression": "{CTR.agent.customerHoldDurationMillis} + {CTR.queue.durationMillis}"
   },
   "Tags": {
   }
}
```

**Average call duration**

```
{
   "CalculatedAttributeName": "_average_call_duration",
   "DisplayName": "Average call duration",
   "Description": "Returns customer's average call duration for voice calls.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "AVERAGE",
   "Conditions": {
      "Range": {
         "Value": 30,
         "Unit": "DAYS"
       },
      "ObjectCount": null
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "disconnectTimestamp"
         },
         {
            "Name": "initiationTimestamp"
         }
      ],
      "Expression": "{CTR.disconnectTimestamp} - {CTR.initiationTimestamp}"
   },
   "Tags": {
   }
}
```

**Customer's maximum hold time**

```
{
    "CalculatedAttributeName": "_maximum_hold_time",
    "DisplayName": "Customer's maximum hold time",
    "Description": "Returns customer's maximum hold time for voice calls in the past month.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "agent.customerHoldDurationMillis"
        },
        {
          "Name": "queue.durationMillis"
        }
      ],
      "Expression": "{CTR.agent.customerHoldDurationMillis} + {CTR.queue.durationMillis}"
    },
    "Statistic": "MAXIMUM",
    "Conditions": {
      "Range": {
        "Value": 30,
        "Unit": "DAYS"
      },
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

## Default profile calculated attribute
<a name="customerprofiles-default-calculated-attributes-profile"></a>

Amazon Connect Customer Profiles provides an out-of-the box default attribute based on a profile. The attributes are as follows:

**New Customer**

```
{
   "CalculatedAttributeName": "_new_customer",
   "DisplayName": "New customer",
   "Description": "Returns true or false for new customer profiles created.",
   "CreatedAt": null,
   "LastUpdatedAt": null,
   "Statistic": "TIME_DIFFERENCE_FROM_NOW",
   "Conditions": {
      "ObjectCount": null,
      "Threshold": {
         "Value": "30",
         "Operator": "LESS_THAN"
      }
   },
   "AttributeDetails": {
      "Attributes": [
         {
            "Name": "createdAt"
         }
      ],
      "Expression": "{_profile.createdAt}"
   },
   "Tags": {
   }
}
```

## Default asset calculated attributes
<a name="customerprofiles-default-calculated-attributes-asset"></a>

Amazon Connect Customer Profiles provides out-of-the box default attributes based on assets. The attributes are as follows:

**Count of assets**

```
{
    "CalculatedAttributeName": "_assets_count",
    "DisplayName": "Count of assets",
    "Description": "Returns the count of assets for a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "AssetId"
        }
      ],
      "Expression": "{_asset.AssetId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Launched": false
  }
```

**First asset purchased date**

```
{
    "CalculatedAttributeName": "_asset_first_occurrence",
    "DisplayName": "First asset purchased date",
    "Description": "Returns purchase date of the customer's first asset.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "PurchaseDate"
        }
      ],
      "Expression": "{_asset.PurchaseDate}"
    },
    "Statistic": "FIRST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**Last asset purchased date**

```
{
    "CalculatedAttributeName": "_asset_last_occurrence",
    "DisplayName": "Last asset purchased date",
    "Description": "Returns purchase date of the customer's last asset.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "PurchaseDate"
        }
      ],
      "Expression": "{_asset.PurchaseDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**Total asset price**

```
{
    "CalculatedAttributeName": "_assets_price_sum",
    "DisplayName": "Total asset price",
    "Description": "Returns customer's total asset price.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Price"
        }
      ],
      "Expression": "{_asset.Price}"
    },
    "Statistic": "SUM",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**Average asset price**

```
{
    "CalculatedAttributeName": "_assets_price_average",
    "DisplayName": "Average asset price",
    "Description": "Returns customer's average asset price.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Price"
        }
      ],
      "Expression": "{_asset.Price}"
    },
    "Statistic": "AVERAGE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**First asset name**

```
{
    "CalculatedAttributeName": "_assets_name_first_occurrence",
    "DisplayName": "First asset name",
    "Description": "Returns name of the customer's first asset",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "AssetName"
        }
      ],
      "Expression": "{_asset.AssetName}"
    },
    "Statistic": "FIRST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**Last asset name**

```
{
    "CalculatedAttributeName": "_assets_name_last_occurrence",
    "DisplayName": "Last asset name",
    "Description": "Returns name of the customer's last asset.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "AssetName"
        }
      ],
      "Expression": "{_asset.AssetName}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

## Default case calculated attributes
<a name="customerprofiles-default-calculated-attributes-case"></a>

Amazon Connect Customer Profiles provides out-of-the box default attributes based on cases. The attributes are as follows:

**Count of cases**

```
{
    "CalculatedAttributeName": "_cases_count",
    "DisplayName": "Count of cases",
    "Description": "Returns the count of customer's cases for a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CaseId"
        }
      ],
      "Expression": "{_case.CaseId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Launched": false
  }
```

**First case created date**

```
{
    "CalculatedAttributeName": "_case_first_occurrence",
    "DisplayName": "First case created date",
    "Description": "Returns created date of the customer's first case.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CreatedDate"
        }
      ],
      "Expression": "{_case.CreatedDate}"
    },
    "Statistic": "FIRST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**Last case created date**

```
{
    "CalculatedAttributeName": "_case_last_occurrence",
    "DisplayName": "Last case created date",
    "Description": "Returns created date of the customer's last case.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CreatedDate"
        }
      ],
      "Expression": "{_case.CreatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**Count of open cases**

```
{
    "CalculatedAttributeName": "_cases_open_status_count",
    "DisplayName": "Count of open cases",
    "Description": "Returns the count of customer's open cases.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CaseId"
        }
      ],
      "Expression": "{_case.CaseId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Status": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Open"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**Count of closed cases**

```
{
    "CalculatedAttributeName": "_cases_closed_status_count",
    "DisplayName": "Count of closed cases",
    "Description": "Returns the count of customer's closed cases.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CaseId"
        }
      ],
      "Expression": "{_case.CaseId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Status": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Closed"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

## Default communication record calculated attributes
<a name="customerprofiles-default-calculated-attributes-communication-record"></a>

Amazon Connect Customer Profiles provides out-of-the box default attributes based on communication records. The attributes are as follows:

**Last email open date**

```
{
    "CalculatedAttributeName": "_campaign_email_last_open",
    "DisplayName": "Last email open date",
    "Description": "Returns the last email open date of the customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Events.Open.UpdatedDate"
        }
      ],
      "Expression": "{_communicationRecord.Events.Open.UpdatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:Email"]
                },
                "Events.Open.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Open"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**Email open count**

```
{
    "CalculatedAttributeName": "_campaign_email_open_count",
    "DisplayName": "Email open count",
    "Description": "Returns the number of times emails were opened by a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CommunicationRecordId"
        }
      ],
      "Expression": "{_communicationRecord.CommunicationRecordId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:Email"]
                },
                "Events.Open.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Open"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**Email delivery count**

```
{
    "CalculatedAttributeName": "_campaign_email_delivery_count",
    "DisplayName": "Email delivery count",
    "Description": "Returns the number of times emails were delivered to a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CommunicationRecordId"
        }
      ],
      "Expression": "{_communicationRecord.CommunicationRecordId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:Email"]
                },
                "Events.Delivery.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["Delivery"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**SMS delivered count**

```
{
    "CalculatedAttributeName": "_campaign_sms_delivery_count",
    "DisplayName": "SMS delivered count",
    "Description": "Returns the number of times SMS were delivered to a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CommunicationRecordId"
        }
      ],
      "Expression": "{_communicationRecord.CommunicationRecordId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ALL",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:SMS"]
                },
                "Events.TEXT_DELIVERED.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["TEXT_DELIVERED"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**Last SMS blocked date**

```
  {
    "CalculatedAttributeName": "_campaign_sms_last_stop",
    "DisplayName": "Last SMS blocked date",
    "Description": "Returns the last SMS blocked date of the customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Events.TEXT_BLOCKED.UpdatedDate"
        }
      ],
      "Expression": "{_communicationRecord.Events.TEXT_BLOCKED.UpdatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ANY",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:SMS"]
                },
                "Events.TEXT_BLOCKED.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["TEXT_BLOCKED"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

**Last SMS carrier blocked date**

```
{
    "CalculatedAttributeName": "_campaign_sms_last_stop_carrier",
    "DisplayName": "Last SMS carrier blocked date",
    "Description": "Returns the last SMS carrier blocked date of the customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "Events.TEXT_CARRIER_BLOCKED.UpdatedDate"
        }
      ],
      "Expression": "{_communicationRecord.Events.TEXT_CARRIER_BLOCKED.UpdatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Filter": {
      "Include": "ANY",
      "Groups": [
        {
          "Type": "ALL",
          "Dimensions": [
            {
              "Attributes": {
                "Attributes.ChannelSubType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["connect:SMS"]
                },
                "Events.TEXT_CARRIER_BLOCKED.EventType": {
                  "DimensionType": "INCLUSIVE",
                  "Values": ["TEXT_CARRIER_BLOCKED"]
                }
              }
            }
          ]
        }
      ]
    },
    "Launched": false
  }
```

## Default order calculated attributes
<a name="customerprofiles-default-calculated-attributes-order"></a>

Amazon Connect Customer Profiles provides out-of-the box default attributes based on orders. The attributes are as follows:

**Count of orders**

```
{
    "CalculatedAttributeName": "_orders_count",
    "DisplayName": "Count of orders",
    "Description": "Returns the count of orders for a customer.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "OrderId"
        }
      ],
      "Expression": "{_order.OrderId}"
    },
    "Statistic": "COUNT",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Launched": false
  }
```

**First order created date**

```
{
    "CalculatedAttributeName": "_order_first_occurrence",
    "DisplayName": "First order created date",
    "Description": "Returns created date of the customer's first order.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CreatedDate"
        }
      ],
      "Expression": "{_order.CreatedDate}"
    },
    "Statistic": "FIRST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**Last order created date**

```
{
    "CalculatedAttributeName": "_order_last_occurrence",
    "DisplayName": "Last order created date",
    "Description": "Returns created date of the customer's last order.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "CreatedDate"
        }
      ],
      "Expression": "{_order.CreatedDate}"
    },
    "Statistic": "LAST_OCCURRENCE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

**Total price of all orders**

```
{
    "CalculatedAttributeName": "_orders_total_price_sum",
    "DisplayName": "Total price of all orders",
    "Description": "Returns sum of total price for all customer's orders.",
    "Statistic": "SUM",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "TotalPrice"
        }
      ],
      "Expression": "{_order.TotalPrice}"
    },
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold":null
    },
    "Launched": false
  }
```

**Orders average of total price**

```
{
    "CalculatedAttributeName": "_orders_total_price_average",
    "DisplayName": "Orders average of total price",
    "Description": "Returns average of total price for all customer's orders.",
    "AttributeDetails": {
      "Attributes": [
        {
          "Name": "TotalPrice"
        }
      ],
      "Expression": "{_order.TotalPrice}"
    },
    "Statistic": "AVERAGE",
    "Conditions": {
      "Range": null,
      "ObjectCount": null,
      "Threshold": null
    },
    "Launched": false
  }
```

# Error messages and resolutions for Amazon Connect Customer Profiles calculated attributes
<a name="customerprofiles-calculated-attributes-troubleshooting"></a>

The following table shows calculated attributes error messages, cause, and resolution for each error.


| Error message | Cause | Resolution | 
| --- | --- | --- | 
| Retrieval of a calculated attribute for a profile shows a null value | This is likely due to the calculated attribute not having data. After creation of a calculated attribute, new data must be ingested. | Ingest new data or re-ingest old data via integrations or the CreateProfile and PutProfileObject APIs. | 