> For the complete documentation index, see [llms.txt](https://help.sdocs.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.sdocs.com/sdocs/advanced-template-logic/related-lists/how-to-format-and-summarize-a-related-list.md).

# How to: Format and Summarize a Related List

Apply column attributes, conditional output, and aggregate SOQL to make related lists easier to read.

Once your query works, improve the output.

Use attributes to format values, handle blanks, and return cleaner tables.

### Format each row

This example formats dates and currency, and replaces empty descriptions.

{% code title="formatted-related-list.xml" %}

```xml
<table class="table1">
  <thead>
    <tr>
      <th>Opportunity</th>
      <th>Stage</th>
      <th>Close Date</th>
      <th>Amount</th>
      <th>Description</th>
    </tr>
  </thead>
  <tbody><!--{{!
<lineitemsSOQL>
  <class>table1</class>
  <soql>
    SELECT Name, StageName, CloseDate, Amount, Description
    FROM Opportunity
    WHERE AccountId = '{{!Account.Id}}'
    ORDER BY CloseDate DESC
    LIMIT 10
  </soql>
  <column>Name</column>
  <column render="RECORD.StageName == 'Closed Won',Won,RECORD.StageName == 'Closed Lost',Lost,RECORD.StageName"></column>
  <column format-date="MMM d, yyyy">CloseDate</column>
  <column prefix="$" format-number="#,###.00">Amount</column>
  <column nullprefix="No description">Description</column>
</lineitemsSOQL>
}}-->
  </tbody>
</table>
```

{% endcode %}

### Build a summary table

Use aggregate SOQL when you need grouped totals instead of row-by-row detail.

{% code title="summary-related-list.xml" %}

```xml
<table class="table1">
  <thead>
    <tr>
      <th>Stage</th>
      <th>Opportunity Count</th>
      <th>Total Amount</th>
    </tr>
  </thead>
  <tbody><!--{{!
<lineitemsSOQL>
  <class>table1</class>
  <soql>
    SELECT StageName, COUNT(Id) dealCount, SUM(Amount) totalAmount
    FROM Opportunity
    WHERE AccountId = '{{!Account.Id}}'
    GROUP BY StageName
    ORDER BY SUM(Amount) DESC
  </soql>
  <column>StageName</column>
  <column>dealCount</column>
  <column format-number="$#,###.00">totalAmount</column>
</lineitemsSOQL>
}}-->
  </tbody>
</table>
```

{% endcode %}

### Best attributes to use first

* `format-number` for currency and numeric output
* `format-date` for date and datetime values
* `prefix` and `postfix` for labels and units
* `nullprefix` for fallback text
* `substitute` for exact value swaps
* `replaceall` for partial text cleanup
* `render` for row-level logic
* `showcolumn` to hide a body column conditionally
* `breakeverynchars` for long URLs or IDs

### Rules to remember

* Any field used in `render` must appear in `SELECT`
* Aggregate values should use aliases like `dealCount`
* `showcolumn` hides body cells only
* Hide the matching header separately when needed

{% hint style="warning" %}
Use `render` only in direct SOQL related lists. Leave the body of that `<column></column>` empty.
{% endhint %}

### Keep going

* Review [Related List Attributes](broken://spaces/WKNnJmhJBQwhdk5WBFsi/pages/vkKv4e3eEWaiLFASBjO6) for attribute details
* Review [Related List Working Examples](broken://spaces/WKNnJmhJBQwhdk5WBFsi/pages/yvRMbTROkJAI3YT3xSEh) for more grouped and conditional patterns


---

# 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://help.sdocs.com/sdocs/advanced-template-logic/related-lists/how-to-format-and-summarize-a-related-list.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.
