Hiding empty columns when ifi condition is determined later in the column

Hi there

I am trying to hide empty columns in export view (see code below for an example of one of the columns ). The logic I am trying to achieve is “if the total of the column is not zero, then show the column in export view”.

The problem I am having is that when the cells above the total are rendered (i.e. the heading and each individual number in the column), the total has not been calculated yet and the variable is still equal to zero. Therefore the cells are always hidden in export view.

Changing the ifi statement to determine whether the total is “not blank” like in the case study also has not worked because there are default values allocated to the cells.

Is there perhaps a way to get around this?

...
{% assign total_non_deductible_23k = 0 %}
...
<table class="usr-width-100">
  <thead>
    <tr>
    ...
      {% ifi total_non_deductible_23k != 0 %} 
          <th class="usr-align-left usr-width-10 usr-line-bottom"><em>Non-deductible interest ito s23K</em></th>
      {% endifi %}
    ...
    </tr>
  </thead>

  <tbody>
    {% fori expense in custom.interest_expenses %}
      {% ifi expense.amount != 0 %}
        <tr>
        ...
        {% ifi total_non_deductible_23k != 0 %}
            <td class="usr-align-right">{% input expense.non_deductible_s23k as:integer default:0 %}{% assign total_non_deductible_23k=total_non_deductible_23k+expense.non_deductible_s23k %}</td>
        {% endifi %}
        ...
        </tr>
      {% endifi %}
    {% endfori %}  
    ...
    <tr>
    ... 
      {% ifi total_non_deductible_23k != 0 %}
        <td class="usr-align-right usr-line-top usr-double-line-bottom"><b>{{ total_non_deductible_23k | integer }}</b></td>
      {% endifi %}
    ...
    </tr>
...
</table>

Hi @NicoleP,

The code is read from top to bottom, so you need to make sure to already assign the total_non_deductible_23k variable before using it in your ifi-statement.

You can do that by already looping through your custom.interest_expenses collection before the table and assigning the expense.non_deductible_s23k to the total_non_deductible_23k variable there.

Then your code would become something like this:

...
{% assign total_non_deductible_23k = 0 %}

{% for expense in custom.interest_expenses %}
	{% assign total_non_deductible_23k = total_non_deductible_23k+expense.non_deductible_s23k %}
{% endfor %}
...
<table class="usr-width-100">
  <thead>
    <tr>
    ...
      {% ifi total_non_deductible_23k != 0 %} 
          <th class="usr-align-left usr-width-10 usr-line-bottom"><em>Non-deductible interest ito s23K</em></th>
      {% endifi %}
    ...
    </tr>
  </thead>

  <tbody>
    {% fori expense in custom.interest_expenses %}
      {% ifi expense.amount != 0 %}
        <tr>
        ...
        {% ifi total_non_deductible_23k != 0 %}
            <td class="usr-align-right">{% input expense.non_deductible_s23k as:integer default:0 %}</td>
        {% endifi %}
        ...
        </tr>
      {% endifi %}
    {% endfori %}  
    ...
    <tr>
    ... 
      {% ifi total_non_deductible_23k != 0 %}
        <td class="usr-align-right usr-line-top usr-double-line-bottom"><b>{{ total_non_deductible_23k | integer }}</b></td>
      {% endifi %}
    ...
    </tr>
...
</table>

Let me know if that worked for you or if you have any other questions!

Kimberly

Hi Kimberly, this worked great. Thank you very much!