# Transaction Item Filters

Transaction item filters are a powerful tool in Open Loyalty that allow you to **narrow down the list of products** included in a transaction before applying rules and effects. These filters work on the **line-item level** within a transaction - letting you isolate products based on attributes like category, price, quantity, brand, or custom values.

## How to Add a Transaction Item Filter

{% stepper %}
{% step %}
In the **Rules & Effects** step of campaign creation, click the **Transaction filters** tab.\
![](/files/p01bNg6ylFbmjxQM3zlI)
{% endstep %}

{% step %}
Select **Add first transaction filter**.\
![](/files/DHOYevKrXWSRfjlCBfeK)
{% endstep %}

{% step %}
Choose the filter type — for example:

* Item category
* Item SKU
* Item name
* Item price
* Item custom attribute
* Item brand

<div align="left"><figure><img src="/files/vBmL5RAUVi8u9mbDyGjL" alt=""><figcaption></figcaption></figure></div>
{% endstep %}

{% step %}
Define your condition or multiple conditions.
{% endstep %}

{% step %}
Save the filter. It will be saved under a label like `Scenario 1` (you can rename it for clarity).
{% endstep %}
{% endstepper %}

***

## How to Use Transaction Filters in Campaign Rules

Once you have defined a transaction filter, you can reference it in both **Conditions** and **Effects**:

### **In Conditions**

You can use the filter to define conditions such as:

* **Quantity of filtered transaction**
* **Value of filtered transaction**

<figure><img src="/files/HllMPXNFOWqPQuMfm2Wp" alt=""><figcaption></figcaption></figure>

For example, set a rule to apply only if:

> Quantity of filtered transaction in *Scenario 1* is greater than 3\
> Value of filtered transaction in *Scenario 1* is at least 100 PLN

This allows for precise rule targeting.

<figure><img src="/files/S0xyMHdBIkA9DYYbMuyp" alt=""><figcaption></figcaption></figure>

### **In Effects**

You can reference filtered items when defining custom effects using expressions like:

```javascript
agg(filter(transaction.items,'scenario_1')).sumBy('grossValue')
agg(filter(transaction.items,'scenario_1')).sumBy('qty')
```

These expressions:

* **Sum the gross value** or **quantity** of the items in the transaction that match the selected filter (`scenario_1`).
* Allow you to create advanced effects based on only a subset of items.

{% hint style="warning" %}
`scenario_1` is a dynamic identifier generated based on the filter name.&#x20;

Always ensure the name you reference in your expression matches the transaction filter’s label.
{% endhint %}

For example, set a rule to reward based on the following criteria:

> Give 1 point for every currency unit (e.g., for every dollar) spent.

<figure><img src="/files/C8qTpRR37HHFPMwL1W3i" alt=""><figcaption></figcaption></figure>

You can also limit how much value or quantity is counted from each matching transaction item using a **cap**.

```javascript
(filter(transaction.items,'scenario_1')).sumBy('grossValue', 1)
(filter(transaction.items,'scenario_1')).sumBy('qty', 1)
```

**Examples:**

* `agg(filter(transaction.items,'filter_name')).sumBy('grossValue', 100)`\
  → Sums up `grossValue` per item, but caps each one at 100
* `agg(filter(transaction.items,'filter_name')).sumBy('qty', 2)`\
  → Counts quantity but caps it at 2 units per item

Use this when you want to prevent unusually high item values or quantities from impacting campaign conditions disproportionately.

## Summary

Transaction item filters help you build smarter, more targeted campaigns by focusing only on specific products within a transaction. You can:

* Define them once and reuse them in multiple rule conditions or effects.
* Create precise campaign logic based on filtered item sets.
* Use them to ensure bonuses or effects only apply to relevant items.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.openloyalty.io/main-features/campaigns/campaigns-and-referral-campaigns/creating-campaigns/transaction-item-filters.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
