Calculated Attributes
Calculated Attributes (formerly Customer Attributes) are customer-level KPIs derived automatically from transaction and event data. They represent aggregated metrics per customer and are available as filter conditions in the audience builder.
- Examples: average cart size, purchase frequency, preferred category, lifetime value, last purchase date.
- Created and managed in Customers → Calculated Attributes.
- Automatically recalculated on a configured schedule as new data arrives.
- Can also be used to power tier systems — any numeric Calculated Attribute can serve as the qualifying metric for a tier.
Use Cases
| Use Case |
|---|
| → Segment customers by average cart size: target those below 30 EUR with an upsell challenge. |
| → Use purchase frequency to identify lapsed customers (< 1 visit/month) for reactivation campaigns. |
| → Calculate preferred category per customer and serve personalized category-level discount campaigns. |
| → Identify customers with high wallet balance but low redemption rate for a points-burning nudge. |
| → Use lifetime value to define VIP tiers and unlock exclusive rewards for top-spending customers. |
| → Predict churn by calculating days since last purchase and flag customers above threshold for re-engagement. |
How It Works
- You define a calculated attribute with a formula (average, sum, count, last value) applied over a time window.
- The platform runs the calculation for every active customer on a configured schedule (e.g., daily) using their transaction and event history.
- The result is stored as a customer-level metric and immediately available in the audience builder.
- Any audience using that attribute is updated on the next sync cycle.
Calculated attributes are only computed for customers with active status, regardless of whether the SQL condition includes non-active customers.
Calculated Attributes list
Go to Customers → Calculated Attributes in Owner. The list shows schedule and last-run information at a glance:
| Column | What it shows |
|---|---|
| Recurrence | Cadence (Daily, Monthly, Custom months, hour interval, or Manual) |
| Schedule (Start – End) | Combined start and end datetime; empty end shows as open-ended |
| Status | Enabled or Disabled (whether scheduled execution is active). Manual rows always show Disabled. |
| Last execution | Date and time of the last run, including the run result (Succeeded, Failed, New) |
From the list you can execute, open details, edit, or delete an attribute (system attributes cannot be edited — see System calculated attributes).
Configuration
Go to Customers → Calculated Attributes → New Attribute in Owner:
| Field | Description |
|---|---|
| Name | Label displayed in the audience builder |
| Formula | Average, sum, count, last value, or custom |
| Source data | Transactions, custom events, or profile fields |
| Time window | Rolling period (last 30 days, last year, lifetime) |
| Calculation schedule | Manual or Scheduled; for Scheduled, configure Enabled, Start, optional End, and Recurrence |
Creating a Calculated Attribute
Only users with the required access can create, edit, and manually execute calculated attributes. Other users may be able to view them but not modify them, depending on company access configuration.
- Go to Customers → Calculated Attributes.
- Click New Customer Attribute in the upper right.
- Fill in the following fields:
Basic Fields
| Field | Description |
|---|---|
| Name | Short display name for the attribute (used in the audience builder and tier setup) |
| Description | Longer text describing the purpose and formula logic |
| Attribute type | Currently only Calculation is available — derived from ingested platform data |
Data Type
After selecting Calculation, choose the data type for the output value:
| Data Type | Use for |
|---|---|
| Number | Any numeric value including decimals (e.g., average cart size: 42.50) |
| Integer | Whole numbers only (e.g., purchase count: 12) |
| String | Text values (e.g., preferred category: "Fresh") |
| Boolean | True/False flags (e.g., has_redeemed_reward: true) |
| Date & time | Date and time values (e.g., last_purchase_date) |
Advanced Fields
| Field | Description |
|---|---|
| Expose calculation results via API | When enabled, the latest calculated value is available via the Streaming API in real time. Useful for loyalty apps and customer service systems that need live attribute data. Note: additional charges may apply. |
| SQL Condition | The SQL query that computes the attribute value per customer. Write or paste the query here. See SQL Condition examples. |
| Profiling consent | If checked, the attribute is calculated for all active customers regardless of whether they accepted profiling consent. |
Calculation Schedule
Schedule controls when the attribute runs. It is separate from Calculation period (which data window the SQL uses).
| Field | Description |
|---|---|
| Calculation period | The time window from which data is pulled (e.g., last 30 days, current month, lifetime). Not to be confused with when the attribute is executed. |
| Execution type | Manual (triggered by an admin at any time) or Scheduled (runs automatically on a cadence) |
Status (Enabled)
| Execution type | Enabled behaviour |
|---|---|
| Manual | Always Disabled and locked. Manual attributes are not on a schedule, so they cannot stay Enabled. |
| Scheduled | You control Enabled / Disabled. Disabled scheduled attributes do not run on the cadence until you turn Enabled on again. |
Extending or changing End does not re-enable the attribute. After the end datetime is reached (or if you change dates while Disabled), set a valid End if needed and turn Enabled on again.
Start, End, and Recurrence (Scheduled only)
For Scheduled execution, configure these blocks in order: Start → End (optional) → Recurrence.
| Block | Fields | Description |
|---|---|---|
| Start | Start date, Start time | When the schedule becomes active (company timezone). The first run is the next recurrence slot on or after this datetime — not necessarily the Start calendar day if that day's slot is already past. |
| End (optional) | End date, End time | Optional stop datetime. Leave empty for no end. When the end is reached, scheduled calculation stops and the attribute becomes Disabled. |
| Recurrence | Cadence | How often the attribute runs after Start. |
Recurrence options:
| Option | Behaviour | Constraints |
|---|---|---|
| Daily | Runs every day at the Start time | — |
| Monthly | Runs on the same day of month as Start | Day of month must be 1–28 |
| Custom months | Runs only in the months you select | Day of month must be 1–28 |
| Hour interval | Runs every N hours | Minimum interval is 2 hours |
Example — first execution: if recurrence is Daily at 16:00 and Start is 1 December 2026, 20:00, the first execution is on 2 December 2026, not on 1 December. On the Start day, that day's 16:00 slot is already past relative to the Start datetime, so the platform waits for the next valid run.
Attributes with Scheduled execution type can still be triggered manually at any time from the main Calculated Attributes page.
- Click Save. The attribute appears in the Calculated Attributes dashboard and becomes visible in customer profiles and the audience builder.
SQL Condition examples
The SQL condition defines how Loyal Guru calculates one value per customer. Use it to transform cart history, rewards usage, category behavior, or custom events into a reusable customer-level attribute.
Each query should return at least:
| Column | Purpose |
|---|---|
customer_id | Identifies which customer receives the calculated value |
value | The attribute value stored on the customer profile |
The Owner SQL placeholder uses %<dataset>s.activities and date placeholders such as %<date_from>s and %<date_to>s. Adapt table names and fields to the company's data model before using a query in production.
| Use case | Data type | Business use |
|---|---|---|
| Average cart amount | Number | Detect low average cart customers and trigger upsell campaigns |
| Purchase frequency | Integer | Identify active, occasional, or lapsed customers |
| Last purchase date | Date & time | Build win-back audiences based on days since last purchase |
| Lifetime value | Number | Feed VIP tiers and high-value customer audiences |
| Preferred category | String | Personalize category-level discounts and recommendations |
| Has purchased in period | Boolean | Exclude recent buyers from reactivation campaigns |
Average cart amount
Use this when you want to segment customers by their average spend per cart.
SELECT
customer_id AS customer_id,
ROUND(AVG(total), 2) AS value
FROM %<dataset>s.activities
WHERE DATE(created_at) BETWEEN %<date_from>s AND %<date_to>s
GROUP BY customer_id;
Purchase frequency
Use this to count how many carts each customer made during the selected calculation period.
SELECT
customer_id AS customer_id,
COUNT(DISTINCT id) AS value
FROM %<dataset>s.activities
WHERE DATE(created_at) BETWEEN %<date_from>s AND %<date_to>s
GROUP BY customer_id;
Last purchase date
Use this to identify recency and build win-back audiences.
SELECT
customer_id AS customer_id,
MAX(created_at) AS value
FROM %<dataset>s.activities
WHERE DATE(created_at) BETWEEN %<date_from>s AND %<date_to>s
GROUP BY customer_id;
Lifetime value
Use this to calculate total customer spend over the selected period. For a lifetime value attribute, configure a broad calculation period.
SELECT
customer_id AS customer_id,
ROUND(SUM(total), 2) AS value
FROM %<dataset>s.activities
WHERE DATE(created_at) BETWEEN %<date_from>s AND %<date_to>s
GROUP BY customer_id;
Has purchased in the period
Use this boolean attribute to exclude customers who already purchased recently, or to trigger campaigns only for active customers.
SELECT
customer_id AS customer_id,
COUNT(DISTINCT id) > 0 AS value
FROM %<dataset>s.activities
WHERE DATE(created_at) BETWEEN %<date_from>s AND %<date_to>s
GROUP BY customer_id;
Preferred category
Use this pattern when cart line/category data is available in the company's dataset. It returns the category with the highest spend per customer in the selected period.
WITH category_spend AS (
SELECT
customer_id,
product_category_name,
SUM(line_total) AS category_total
FROM %<dataset>s.activity_lines
WHERE DATE(created_at) BETWEEN %<date_from>s AND %<date_to>s
GROUP BY customer_id, product_category_name
),
ranked_categories AS (
SELECT
customer_id,
product_category_name,
ROW_NUMBER() OVER (
PARTITION BY customer_id
ORDER BY category_total DESC
) AS rank
FROM category_spend
)
SELECT
customer_id AS customer_id,
product_category_name AS value
FROM ranked_categories
WHERE rank = 1;
The examples are templates. Validate SQL syntax, table names, category fields, and date logic with your implementation team or Customer Success Manager before enabling the attribute in production.
Calculation history retention
Each calculation run stores one snapshot per Customer. Audiences, the customer profile, tiers, challenges, and the Streaming API always use the latest value. The platform also keeps a limited history of past snapshots and deletes older ones automatically.
This does not delete the attribute definition, source carts or custom events, or the current value used in the product.
| Recurrence | Snapshots kept | Approximate window if the schedule is regular |
|---|---|---|
| Daily | Last 60 executions | About 2 months |
| Monthly | Last 24 executions | About 2 years |
| Custom months | Last 5 executions | Last 5 runs |
| Manual | Last 5 executions | Last 5 runs |
Downstream exports or BigQuery queries that join historical calculated-attribute rows only see this retained window. You cannot reconstruct a full time series of past calculations beyond it.
System calculated attributes
System calculated attributes cannot be edited in Owner. Edit is blocked in the UI and rejected by the API.