# MailMerge: Using Filters to Remove Unwanted Rows

> TX Text Control merge block filters remove unwanted rows from repeating data during the mail merge process without modifying the underlying source. Filter conditions applied to merge blocks selectively exclude rows based on field values, keeping output documents precisely formatted.

- **Author:** Bjoern Meyer
- **Published:** 2019-06-04
- **Modified:** 2026-07-17
- **Description:** TX Text Control merge block filters remove unwanted rows from repeating data during the mail merge process without modifying the underlying source. Filter conditions applied to merge blocks selectively exclude rows based on field values, keeping output documents precisely formatted.
- **2 min read** (321 words)
- **Tags:**
  - ASP.NET
  - Mail Merge
  - Reporting
  - Windows Forms
  - WPF
- **Web URL:** https://www.textcontrol.com/blog/2019/06/04/mailmerge-using-filters-to-remove-unwanted-rows/
- **LLMs URL:** https://www.textcontrol.com/blog/2019/06/04/mailmerge-using-filters-to-remove-unwanted-rows/llms.txt
- **LLMs-Full URL:** https://www.textcontrol.com/blog/2019/06/04/mailmerge-using-filters-to-remove-unwanted-rows/llms-full.txt

---

Consider a use case where you don't have any influence on the structure of data you get from applications, APIs or other business layers to merge your templates for invoices or other reports.

In the following scenario, an invoice should be created based on JSON data from an ERP system. All invoice items are returned as line items plus a last line item that only contains the total price. The following JSON is used as a data source. In line 23-25, you can see a line item that only contains a price. This is the line in the final document we would like to filter out.

```
[
  {
    "Id":1,
    "Name":"Invoice",
    "Orders":[
      {
        "Id":1,
        "OrderItems":[
          {
            "Id":1,
            "Qty":5,
            "Product":{
              "Id":1,
              "Name":"TX Spell .NET",
              "Description":"Spell checking component",
              "Available":true,
              "Price":249.56,
              "Serial":"AA6765653"
            },
            "Price":200.56
          },
          [...],
          {
            "Price":4433.44
          }
        ]
      }
    ]
  }
]
```

As the total price should be calculated using a formula in the template, the last "line item" is not required. The following screenshot shows the template with the repeating block:

![Template](https://s1-www.textcontrol.com/assets/dist/blog/2019/06/04/a/assets/template.webp "Template")

After the data is merged into this template as is, the results show the "empty" line displaying only the total value:

![Template](https://s1-www.textcontrol.com/assets/dist/blog/2019/06/04/a/assets/results.webp "Template")

In order to remove this empty line, it is not required to manipulate the data. A merge block filter can be used to filter out the empty line. The block *OrderItems* is receiving a filter on the column *Qty*. If this field is empty, the row should not be rendered:

![Template](https://s1-www.textcontrol.com/assets/dist/blog/2019/06/04/a/assets/filter.webp "Template")

The following screenshot shows the filtered results:

![Template](https://s1-www.textcontrol.com/assets/dist/blog/2019/06/04/a/assets/results-filtered.webp "Template")

You can download the template and the sample JSON [here](https://s1-www.textcontrol.com/assets/dist/blog/2019/06/04/a/assets/filter-data.zip) for your own tests.

---

## About Bjoern Meyer

As CEO, Bjoern is the visionary behind our strategic direction and business development, bridging the gap between our customers and engineering teams. His deep passion for coding and web technologies drives the creation of innovative products. If you're at a tech conference, be sure to stop by our booth - you'll most likely meet Bjoern in person. With an advanced graduate degree (Dipl. Inf.) in Computer Science, specializing in AI, from the University of Bremen, Bjoern brings significant expertise to his role. In his spare time, Bjoern enjoys running, paragliding, mountain biking, and playing the piano.

- [LinkedIn](https://www.linkedin.com/in/bjoernmeyer/)
- [X](https://x.com/txbjoern)
- [GitHub](https://github.com/bjoerntx)

---

## Related Posts

- [MailMerge: Conditional Table Cell Colors using Filter Instructions](https://www.textcontrol.com/blog/2019/06/06/mailmerge-conditional-table-cell-colors-using-filter-instructions/llms.txt)
- [Different Ways to Create Documents using Text Control Products](https://www.textcontrol.com/blog/2017/10/17/ways-to-create-documents-using-text-control-products/llms.txt)
- [TX Text Control 32.0 Has Been Released](https://www.textcontrol.com/blog/2023/09/13/tx-text-control-320-has-been-released/llms.txt)
- [An Ultimate Guide to Mail Merge with MS Word Documents in C#](https://www.textcontrol.com/blog/2023/06/07/an-ultimate-guide-to-mail-merge-with-ms-word-documents-in-csharp/llms.txt)
- [TX Text Control 31.0 and TX Spell .NET 10.0 Have Been Released](https://www.textcontrol.com/blog/2022/09/07/tx-text-control-31-released/llms.txt)
- [Mail Merge with MS Word Documents in C# - An Ultimate Guide](https://www.textcontrol.com/blog/2022/05/25/mail-merge-with-ms-word-documents-in-csharp-an-ultimate-guide/llms.txt)
- [Combining MailMerge and Table of Contents](https://www.textcontrol.com/blog/2022/03/22/combining-mailmerge-and-table-of-contents/llms.txt)
- [Merging Form Fields using the MailMerge Class](https://www.textcontrol.com/blog/2022/02/21/merging-form-fields-using-the-mailmerge-class/llms.txt)
- [MailMerge: Rendering Conditional Table Rows](https://www.textcontrol.com/blog/2022/02/17/mailmerge-rendering-conditional-table-rows/llms.txt)
- [TX Text Control 30.0 and TX Spell .NET 9.0 Have Been Released](https://www.textcontrol.com/blog/2021/11/29/tx-text-control-30-released/llms.txt)
- [TX Text Control X19 and TX Spell 8.0 Have Been Released](https://www.textcontrol.com/blog/2020/12/02/tx-text-control-x19-released/llms.txt)
- [TX Text Control X18 has been Released](https://www.textcontrol.com/blog/2020/03/16/tx-text-control-x18-released/llms.txt)
- [TX Text Control X17 has been Released](https://www.textcontrol.com/blog/2019/05/28/tx-text-control-x17-released/llms.txt)
- [Create and Modify Adobe PDF Documents within your .NET Application](https://www.textcontrol.com/blog/2019/05/27/create-and-modify-adobe-pdf-documents/llms.txt)
- [Creating Templates: Typical Invoice Elements](https://www.textcontrol.com/blog/2019/04/16/typical-invoice-elements/llms.txt)
- [Text Control Roadmap 2019: High DPI Support, Forms, Node.js and Angular](https://www.textcontrol.com/blog/2019/03/12/text-control-roadmap-2019/llms.txt)
- [TX Text Control X16 and TX Barcode .NET 5.0 Released](https://www.textcontrol.com/blog/2018/11/14/tx-text-control-x16-and-tx-barcode-net-50-released/llms.txt)
- [Generate Word Documents from Templates in .NET](https://www.textcontrol.com/blog/2018/08/10/generate-word-documents-from-templates-in-net/llms.txt)
- [Sneak Peek X16: Filter and Sort MergeBlock Rows](https://www.textcontrol.com/blog/2018/04/26/sneak-peek-x16-filter-and-sort-mergeblock-rows/llms.txt)
- [X15: Merging Data into Chart Objects](https://www.textcontrol.com/blog/2018/01/05/merging-data-into-charts/llms.txt)
- [TX Text Control X15 and TX Spell .NET 7.0 Released](https://www.textcontrol.com/blog/2017/12/13/tx-text-control-x15-and-tx-spell-net-70-released/llms.txt)
- [Sneak Peek X15: MS Word Compatible Document Protection and Editable Regions](https://www.textcontrol.com/blog/2017/11/16/ms-word-compatible-editable-regions/llms.txt)
- [X14 Preview: Build Your Own Template Designer with the New DataSourceManager Class](https://www.textcontrol.com/blog/2016/11/15/x14-preview-build-your-own-template-designer-with-the-new-datasourcemanager-class/llms.txt)
- [TX Text Control 34.0 SP4 is Now Available: What's New in the Latest Version](https://www.textcontrol.com/blog/2026/05/20/tx-text-control-34-0-sp4-is-now-available/llms.txt)
- [TXTextControl.Markdown.Core 34.1.0-beta: Work with Full Documents, Selection, and SubTextParts](https://www.textcontrol.com/blog/2026/04/14/txtextcontrol-markdown-core-34-1-0-beta-work-with-full-documents-selection-and-subtextparts/llms.txt)
