---
title: "Remove empty table columns"
description: "Hide empty table columns based on data values so generated documents and display only relevant information in tables."
canonical_url: "https://resources.docmosis.com/template-tutorials/conditional-columns-2"
last_reviewed: 2026-06-08
---
# Remove empty table columns
The [Conditional Columns](/template-tutorials/conditional-columns) article covered how to include or exclude columns in a table using Boolean fields and expressions.
However, sometimes a column may need to be excluded from a table when there is no data to display anywhere in that column.
This can be achieved by adding a \<\\>.
2. Use a repeating section to loop through the customers data: \<\\>…\<\\>.
3. Use a conditional section to check if the middle name is not blank: \<\\>.
4. Set the variable to true when a middle name is not blank: \<\<$mNamesExist\=true\>\>.
5. Use a conditional column directive \<\\> in the table’s header row, that is based on the variable $mNamesExist.
If there are any middle names in the data, the column is shown, otherwise not. In the supplied data file, no middle name exists, so the column is hidden.
### Example 2
This example shows how to display the “Discount” column in a table of products if at least one product row has a discount value. To achieve this, first add up all of the discount values, then show the column if the total discount is greater than zero.
The steps to achieve this are:
1. Create a new variable called $discountTotal with an initial value of 0: \<\<$discountTotal\=0\>\>.
2. Use a repeating section to loop through the data: \<\\>…\<\\>.
3. Add the discount value to the total discount variable: \<\<$discountTotal \={$discountTotal\+ifBlank(discount,0\)}\>\>. \
The ifBlank() function used within the expression converts the value of discount to 0 if it’s null or blank.
4. Use a conditional column directive \<\0}\>\> in the table's header row, that is based on the variable $discountTotal.
If there are any discounts in the data, the column is shown, otherwise not. In the supplied data file, no discount exists for any of the products. This results in $discountTotal \= 0, so that the "Discount" column is hidden.
Note: this method of calculating column totals can also be used to display totals in the final row of a table.\
# Remove empty table columns - related json data
```json
{
"customers": [
{
"fName": "Paul",
"mName": "",
"lName": "Thomas",
"city": "Perth",
"postCode": "6000"
},
{
"fName": "Chris",
"mName": "",
"lName": "Howard",
"city": "Sydney",
"postCode": "2000"
},
{
"fName": "Sue",
"mName": "",
"lName": "Richards",
"city": "Perth",
"postCode": "6000"
}
],
"products": [
{
"product": "Apple",
"productID": "AP",
"quantity": "100",
"discount": null,
"price": "0.5"
},
{
"product": "Orange",
"productID": "OR",
"quantity": "150",
"discount": null,
"price": "0.6"
},
{
"product": "Bannana",
"productID": "BA",
"quantity": "100",
"discount": null,
"price": "0.7"
}
]
}
```
# Remove empty table columns - example template syntax
```docmosis
**Conditional Columns Part 2**
**\<\\>
\<\\>
\<\\>
\<\<$mNamesExist\=true\>\>
\<\\>
\<\\>
| **First Name** | **Middle Name****\<\\>** | **Last Name** | **City** | **Post Code** |
| --- | --- | --- | --- | --- |
| \<\\> | | | | |
| \<\\> | \<\\> | \<\\> | \<\\> | \<\\> |
| \<\\> | | | | |
Example 2
\<\<$discountTotal\=0\>\>
\<\\>
\<\<$discountTotal \={$discountTotal\+ifBlank(discount,0\)}\>\>
\<\\>
| **Product** | **Product ID** | **Quantity** | **Discount****\<\0}\>\>** | **Price****\<\<$priceTotal\=0\>\>** |
| --- | --- | --- | --- | --- |
| \<\\> | | | | |
| \<\\> | \<\\> | \<\\> | \<\<{numFormat( discount, ‘$\#,\#\#0\.00’)}\>\> | \<\<{numFormat(price, ‘$\#,\#\#0\.00’)}\>\>\<\<$priceTotal \= {$priceTotal \+ price}\>\> |
| \<\\> | | | | |
| **Total:** | | | **\<\<{numFormat( $discountTotal, ‘$\#,\#\#0\.00’)}\>\>** | **\<\<{numFormat( $priceTotal, ‘$\#,\#\#0\.00’)}\>\>** |
```