# How to Add a Subtotal Row to a DOCX Table

Use `tableend` when you want a subtotal or total to stay attached to a DOCX table.

This pattern helps grouped table content render as one complete table.

It also avoids the extra line break that can appear between separate Word tables.

### When to use this

Use this pattern when:

* a DOCX related list ends with a subtotal row
* a final total should appear as part of the same table
* grouped rows should read as one continuous table

### Basic pattern

Place a closing `tableend` block after the main DOCX table.

Insert the subtotal or total table inside that block.

<pre class="language-plaintext" data-title="docx-tableend-pattern.txt"><code class="lang-plaintext"><strong>[&#x3C;tableend>]
</strong>INSERT TABLE HERE
[&#x3C;/tableend>]
</code></pre>

`INSERT TABLE HERE` should be a Word table.

Match its column widths and formatting to the main table.

### How it works

1. Build your main DOCX table with the normal table syntax.
2. Add the `tableend` wrapper after that table.
3. Insert a one-row table for the subtotal or total.
4. Add your label and merge field values in that row.

### Example use case

Use this when a product table needs a final summary row like `Subtotal` or `Grand Total`.

The summary row stays visually connected to the rows above it.

#### Example:&#x20;

```
[{{!<lineitemsSOQL>
<tableformat>]

| Product  | Quantity | SubTotal |
| apples   | 4        | $4       |
| oranges  | 6        | $12      |

[</tableformat>
<soql>
  SELECT Product2.Name, Quantity, TotalPrice
  FROM OpportunityLineItem
  WHERE OpportunityId = '{{!Opportunity.Id}}'
  ORDER BY SortOrder
</soql>
<column>Product2.Name</column>
<column>Quantity</column>
<column format-number="#,##0.00" prefix="$">TotalPrice</column>
</lineitemsSOQL>}}]
[<tableend>]
|          |          |    Total |
|          |          |    $16   |
[</tableend>]
```

### Tips

* Keep the subtotal table structure aligned with the main table.
* Use the same borders and cell padding for a seamless result.
* Test in Word after upload to confirm the rows appear as one table block.

### Related articles

* [Microsoft Word (DOCX)](/sdocs/template-architecture/document-formats/docx-s-docs.md)
* [How to: Create a Table In Microsoft Templates (DOCX, PPTX)](/sdocs/advanced-template-logic/related-lists/how-to-create-a-table-in-microsoft-templates-docx-pptx.md)


---

# 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/template-architecture/document-formats/docx-s-docs/additional-resources/add-a-subtotal-line-to-the-end-of-a-table-in-docx.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.
