# How to: Format and Summarize a Related List

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