> For the complete documentation index, see [llms.txt](https://helpcenter.channable.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://helpcenter.channable.com/manage-improve-product-data/rules-bulk-edit-and-enrich/how-to-use-actions-then-in-rules/math-actions/rule-action-item-group-rules.md).

# Rule action: Item group rules

Calculate counts, totals, and extreme values across items that share a group identifier.

Use **`Calculate item group`** to calculate values across items that share a group identifier.

This action is useful for tasks such as:

* Counting the items in a group.
* Calculating a total, highest, or lowest value across a group.

Before you use this action, create or populate a field that identifies each group. For example, use `item_group_id` to give every vacancy with the same branch and city the same value.

***

## Example `Calculate item group` use cases

### Count vacancies by location

First, create a rule that sets `item_group_id` for each vacancy. Give vacancies from the same branch and city the same `item_group_id` value.

#### How to build a rule

* Condition: **`For all items`**
* Action: THEN **`Calculate item group`** in `item_group_id` **`Count items`** and store in `item_group_count`

The action stores the number of items in each group in `item_group_count`.

You can also use this action to:

* Count houses by property type and area.
* Count accommodations by city.
* Count tickets by route.

### Calculate total stock for a product

Use this action after you create an `item_group_id` for each product group. Select the numeric field to add, then select a field to store the group total.

#### How to build a rule

* Condition: **`For all items`**
* Action: THEN **`Calculate item group`** in `item_group_id` **`Calculate sum`** of `stock` and store in `total_stock`

The action adds the `stock` values from every item with the same `item_group_id`. For example, ten items with a `stock` value of three each have a `total_stock` value of `30`.

### Find the lowest group price

Use this action to find the lowest value in a group and store it on every item in that group. For example, find the lowest flight price across dates and offers, then use `lowest_price` in advertising copy.

#### How to build a rule

* Condition: **`For all items`**
* Action: THEN **`Calculate item group`** in `item_group_id` **`Find lowest value`** of `price` and store in `lowest_price`

All items remain in the group. This action stores the value; it does not remove duplicate items.

### Find the highest group price

Use this action to find the highest value in a group. It works the same way as **`Find lowest value`**, but stores the maximum value instead.

#### How to build a rule

* Condition: **`For all items`**
* Action: THEN **`Calculate item group`** in `item_group_id` **`Find highest value`** of `price` and store in `highest_price`

### Available calculations

Select one of the following subactions:

* **`Count items`** counts the items in each group.
* **`Calculate sum`** adds the values in a numeric field for each group.
* **`Find highest value`** stores the highest value from each group.
* **`Find lowest value`** stores the lowest value from each group.

{% hint style="info" %}

#### Important details

Select **Sort numbers** when you use **`Find highest value`** or **`Find lowest value`** with a numeric field. These actions keep all items and store the calculated value in a field.
{% endhint %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://helpcenter.channable.com/manage-improve-product-data/rules-bulk-edit-and-enrich/how-to-use-actions-then-in-rules/math-actions/rule-action-item-group-rules.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
