**Aggregates** are custom _customer_ attributes that are calculated from already existing data. They help you calculate aggregated information for every customer. An example of aggregate would be calculating a customer's lifetime value: In your report, you would use `sum>purchase>total_price`.

**Running aggregates** are custom _event_ attributes, which is the main difference to aggregates. They help you calculate aggregated information for any event. Running aggregates can be used in almost any analytical part of Bloomreach Engagement.

Aggregate typesColumn Title
minimum / maximumReturns the smallest / biggest value from the dataset.
sumSums values in the dataset. For example, `sum > purchase > total_price` will return the total spend.
countCount the number of data points. For example, `count > purchase` will return the number of purchases.
avg (average)Returns the average of all values of that specific event.
first / lastReturns the value of the first / last occurrence of that event.
existsReturns either 1 or 0. For example, if a customer never purchased before, then `exists > purchase` will return 0 and vice versa.
most commonReturns the most common value, such as the most viewed item.
count distinctThis counts distinct values in a data set, such as how many different categories a specific customer viewed.
distinct valuesLists all the unique values within an aggregate.

For the `most common` aggregate type, in case there are two (or more) equal outcomes, Bloomreach Engagement picks the first one that occurred in the event history.

When using decimal numbers, make sure to denote them by `.` (e.g. `12.34`) as otherwise, `sum` , `avg` or other mathematical aggregates will not work properly

Grasping aggregates and running aggregates and the difference between them might be a bit tricky at the beginning. That's why we created this short video that explains the topic for you. We do recommend watching it as you will be using (running) aggregates very often in Bloomreach Engagement.

# How to create a (running) aggregate

It can be created in two ways:

  • Go to `Data & Assets` > `Data manager` > `Definitions` > `New definition`.

  • Aggregates/running aggregates can also be created when selecting customer attributes/events for your analysis wherever it is possible. If you wish, you can also save them for later use (so next time it appears in the list) by clicking on the save button as shown below.


Aggregates can be found under the`CUSTOMER` while running aggregates are under `EVENT`

The process of creating an aggregate is simple:

(Script tags will be stripped)

## Running aggregates: The difference between including/excluding the event itself

Running aggregates contain one additional setting, which is deciding whether to include or exclude the event itself from the calculation. This setting is relevant when the anchor event is identical to the event from which the running aggregate is calculated. See the 2 Use Cases about calculating revenue and conversion rate by country [below](🔗) for a better understanding.

## 'Skip first' function

You can skip any number of values for the `first`, `last` and `most common` aggregates. For example, you can use the aggregate "first purchase timestamp > skip 1", which will give you the timestamp of the second purchase of that particular customer.

For distinct aggregate, it has 100% precision if there are less than 10k unique values. If there are more values, it has around 97% precision.

# Grouping by Attribute

### What are Aggregates Grouped by Attribute

The Grouping feature empowers you to craft an aggregate that efficiently **organizes events based on specific attributes.** This enables the aggregation of values exclusively from **either the initial or latest event in the group for each customer.** It's important to note that event grouping can only utilize **attributes visible within the Data Manager schema**, excluding the option to group events by special attributes. This restriction ensures that your aggregation remains closely aligned with the available data fields.

### Why use Aggregates Grouped by Attribute

“Group by attribute” will let you segment your audience by looking at a series of updates of an event (e.g., travel booking) and filter based on the first or last update to the event. A powerful update to Bloomreach’s aggregates functionality, this feature will help you answer questions like: ‘find customers flying to Dubai in June’, automatically removing anyone who has booked and canceled their trip already, or ‘segment customers with high spend’, automatically excluding returns.

### How Aggregates Grouped by Attribute work

  1. Create an Aggregate:

    1. Define aggregation, event type, and filters.

  2. Enable Grouping:

    1. Select an event attribute for grouping.

    2. Choose to aggregate values from either the First or Last event in each group.

  3. Save the Aggregate:

  4. Use this aggregate as a normal one.

[Aggregates](🔗) can be used for personalization through Jinja, as well as for analytics.


Look at the customer's bookings below. There are 4 events, and they're organized from newest to oldest. 2 events share the same ID (123 or 456) but they go to different places. If you want the latest destination for each group, you can group the events by ID as below.

Then, instead of looking at all the events, the feature only looks at the last one in each bundle with the same ID. It's like finding the newest info for each type of booking. The feature applies the event filter you chose in the aggregate, in this case, the event 'booking'.

# Example use cases

## Aggregates

Aggregates can be used for filtering and segmenting customers or in expressions. They are usually used in campaign filters. Check out these examples to see what kind of insights are available through aggregates. Notice every analysis related to a customer.

**How many purchases does a customer have in total?**

**How many times customer visited our page in the last 30 days?**

**What is a customer’s total lifetime value?**

**What is the average customer purchase when using loyalty points for purchase?**

**What was the referrer of a customer’s first visit to the webpage?**

**How many emails has the customer received from us in the last 14 days?**

**What was the last product the customer viewed?**

## Running aggregates

### **What is the revenue per country?**

If you don't track `country` as an attribute of the `purchase` event, then you need to retrieve it from the `session_start` event using a running aggregate. For every purchase in the past Bloomreach Engagement will look a the `last session_start > country` that preceded that purchase and will attribute that purchase to the country which is tracked there.

**Note:** Changing the `including/excluding` operator does not make a difference here. Read the next use case for further explanation.

### **What is the conversion rate per country?**

The metric (conversion rate) is, in this case, a formula that uses two types of events – session_start and purchase – meaning that the report cannot be broken down by an attribute of one, or the other. As mentioned above, the attribute ‘country’ is tracked for event session_start, but usually not for event purchase.

The running aggregate you will need for this report looks like this:

Here, it is crucial to switch from excluding to including. We essentially have two anchor events in this case – `session_start` and `purchase`. The running aggregate will look for the country of the `last session_start` both before every `purchase` event and before every `session_start` event, **including** that very event. In other words, the `including/excluding` setting matters here because the running aggregate is calculated from one of the anchor events - `session_start`.

The report will look like this:

You may have noticed that, in this case, you have to insert the running aggregate into Rows, before inserting the Metric. Once you insert a formula that uses two types of events under Metrics, you won't be able to choose an event attribute (or running aggregate) under Rows anymore. So make sure to start with Rows in such cases.

### **What was the referrer for the last session_start of this event (for example: purchase)?**

### **When was the last time a specific weblayer was viewed by any customer?**

### **When was the last time an email was delivered to any customer?**

## Grouping by attribute

  • **Travel Companies: **Track new events for updates on trips, flights, or accommodations.

  • **Insurance Companies:** Maintain a record of the latest state of contracts.

  • **Count Purchase Aggregation:** Create an aggregate for each user to get the number of purchases. Without this feature, you would also count purchases that have resulted in a return (Success - Return). However, with 'Group by' you can exclude such purchases like this:

    • Count Purchase

      • Where `Status = Success`

    • Group by ID and aggregate only the most recent events (Last events). This ensures that purchases marked as "Success" are genuinely the latest ones, and any subsequent "Return" status events are excluded.