> For the complete documentation index, see [llms.txt](https://university.gonexa.fr/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://university.gonexa.fr/doc/en/getting-started/manage-tables/group-table-data.md).

# Group table data

Group all the items of a child object that match a criterion, i.e. group the rows of a table in a Word document by a Salesforce field such as the product family.

{% embed url="<https://www.youtube.com/watch?v=BEx0r0F6GKk>" %}

## Group items by a Salesforce criterion

Group all the items of a child object that match a criterion, i.e. group the rows of a table in a Word document by a Salesforce field such as the product family, for example.

From the child object of your document template:

* Go back to the child object you want to group
* Choose the Salesforce field to group by. It can be a field of the child object or of one of its parent objects.

{% hint style="success" %}
**Example**

`Product2.Family`
{% endhint %}

* Name the "Group Name" field as you wish, for example "Groupe".

![Grouping setup in Salesforce](https://content.gitbook.com/content/U1Chwyf7Cc7FN9BiEh0V/blobs/U676OND2X1QTr2jFl1T6/20-06-groupement-salesforce.gif)

From your document template, build your table using one of the following two methods.

{% tabs %}
{% tab title="#1 Without header repetition" %}

## #1 Without header repetition

If you do not need to repeat the table headers across several tables, this method is recommended as it is the simplest.

* In your Word document template, create a table with one column and two rows, the first row containing the group name.

{% hint style="success" %}
**Example**

The first row of the table will contain the tag `{!Nom du groupe | Nom Api du champ sur lequel grouper}` (group name | API name of the field to group by), which in our case is `{!Groupe|Product2.Family}`
{% endhint %}

* In the 2nd row of the table, insert the entire table (header, columns and rows) containing the child objects
* Adjust the borders and columns as you like using Word formatting.

![Grouping example, method 1](https://4198981723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYUzkIngX1MnHE8kOJDR%2Fuploads%2FUb2WRCWUSUnDH1kPZz8Z%2Fgerer-tableaux-7.png?alt=media)

![Grouping without header repetition](https://content.gitbook.com/content/U1Chwyf7Cc7FN9BiEh0V/blobs/x0SN0AQmIrkUdJHpUAiS/21-07-sans-repetitions-d-entetes.gif)

[Grouping template - #Method 1](https://cdn.prod.website-files.com/6266bdee7bba3ff58801d972/675abd17978157b22038a5e6_Template%20Gonexa%20-%20Mode%CC%80le%20de%20devis%20-%20Groupement%20Me%CC%81thode%201.docx)
{% endtab %}

{% tab title="#2 With header repetition management" %}

## #2 With header repetition management

If you want to manage the repetition of table headers across several pages, you must use this method. The entire table will be repeated according to the number of results matching the criterion, with the family name in the header.

* In your Word document template, create a table with one column and three rows, and enter the grouping tag in the 1st row.

{% hint style="success" %}
**Example**

The first row of the table will contain the tag `{!Nom du groupe | Nom Api du champ sur lequel grouper}` (group name | API name of the field to group by), which in our case is `{!Groupe|Product2.Family}`
{% endhint %}

* In the 2nd row of the table, split the cell according to the number of columns you want
* In the 3rd row of the table, insert the table of your child object containing the child tags, adjusting the columns and borders. You can also change the table properties by setting "Text wrapping" to "Around"

![Grouping example, method 2](https://4198981723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYUzkIngX1MnHE8kOJDR%2Fuploads%2F7jh8msLnZXYqsBfnAVdL%2Fgerer-tableaux-8.png?alt=media)

![Grouping with header repetition](https://content.gitbook.com/content/U1Chwyf7Cc7FN9BiEh0V/blobs/1STcgmlUkAk1bwyOioZV/22-08-avec-repetitions.gif)

Download the example template:

[Grouping template - #Method 2](https://cdn.prod.website-files.com/6266bdee7bba3ff58801d972/675abda35169f1b0fccc6a93_Template%20Gonexa%20-%20Mode%CC%80le%20de%20devis%20-%20Groupement%20Me%CC%81thode%202.docx)

![Final grouping result](https://4198981723-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FTYUzkIngX1MnHE8kOJDR%2Fuploads%2FeqUnYsMhbbWUzxkTaa1k%2Fgerer-tableaux-9.png?alt=media)
{% endtab %}
{% endtabs %}


---

# 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://university.gonexa.fr/doc/en/getting-started/manage-tables/group-table-data.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.
