# CASE: hide columns when empty

**URL:** <https://community.silverfin.com/t/case-hide-columns-when-empty/1916>\
**Category:** Cases\
**Tags:** hide, tables\
**Created:** [September 14, 2020, 3:29pm UTC](https://community.silverfin.com/t/case-hide-columns-when-empty/1916 "2020-09-14T15:29:16Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![sven](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/sven/32/1495_2.png) [@sven](https://community.silverfin.com/u/sven)\
**Post date:** [September 14, 2020, 3:29pm UTC](https://community.silverfin.com/t/case-hide-columns-when-empty/1916/1 "2020-09-14T15:29:16Z")

</div>

You might find yourself building a table, where some columns can hold information but not always have information in them. While that’s just fine in input-mode, in export they take in some space we might need, so what’s the point on exporting them to PDF if they don’t hold anything of information?

Well, with an `IFI-statement` we can do just that (more info [here](https://developer.silverfin.com/docs/control-flow#ifi)), but we will need to check each column separately to see if indeed the column holds at least one time data.

With below code we can do just that:

```auto
{% assign show_statement_col = false %}
{% for account in bank_accounts %}
  {% if account.custom.bank.docs.document != blank %}
    {% assign show_statement_col = true %}{% break %}
  {% endif %}
{% endfor %} 

```

in which we first set a variable to false to be used later in in our ifi-statement:

> {% assign show\_statement\_col = false %}

and then loop over our collection:

> {% for account in bank\_accounts %}  
> …  
> {% endfor %}

to find if something actually has data:

> {% if account.custom.bank.docs.document != blank %}

as soon as it does, we assign that variable `show_statement_col` to _true_:

> {% assign show\_statement\_col = true %}

and stop looping over our collection with the break-tag:

> {% assign show\_statement\_col = true %}{% break %}

We do this because it makes no sense looping through all loops if you find data already.

Now, the second column has deliberately been set without a fixed width, as the whole table has been set on 100%, so this column will take the remainder of what’s left of 100%.

A more in depth case here:

```auto
{% comment %}some needed logic{% endcomment %}
{% assign bank_accounts = #5 %}

{% comment %}check if the last columns are needed or not{% endcomment %}
{% assign show_statement_col = false %}
{% for account in bank_accounts %}
  {% if account.custom.bank.docs.document != blank %}
    {% assign show_statement_col = true %}{% break %}
  {% endif %}
{% endfor %}

{% assign show_statement_1d_col = false %}
{% for account in bank_accounts %}
  {% if account.custom.bank.docs_plus_1d.document != blank %}
    {% assign show_statement_1d_col = true %}{% break %}
  {% endif %}
{% endfor %}

{% comment %}
==================
      TABLE
==================
{% endcomment %}
{% stripnewlines %}
|----30%----
|-----------
|----15%----:
{% ifi show_statement_col %}
  |----20%----:
{% endifi %}
{% ifi show_statement_1d_col %}
  |----20%----:
{% endifi %}+
{% newline %}
|_ {% t "Account" %} _
|_ &nbsp; _
|_ {% t "Value" %}                 
{% ifi show_statement_col %}
  _|_ {% t "Bank statement" %}         
{% endifi %}
{% ifi show_statement_1d_col %}
  _|_ {% t "Bank statement +1" %}     
{% endifi %} _

{% for account in bank_accounts %}
  {% newline %}
  | {{ account.link }}
  | &nbsp;
  | {{ account.value | currency_dc }}
  {% ifi show_statement_col %}
    | {% input account.custom.bank.docs as:file %}
  {% endifi %}
  {% ifi show_statement_1d_col %}
    | {% input account.custom.bank.docs_plus_1d as:file %}  
  {% endifi %}
  
  {% comment %}assign values to variable{% endcomment %}
  {% assign total_bank = total_bank+account.value %}
  
  {% if forloop.last %}
    {% newline %}
    |
    |
    |_^ {{ total_bank | currency_dc }} ^_
  {% endif %}
{% endfor %}
{% endstripnewlines %} 

```
