Logic to hide blank lines in a table

{% assign accounts = period.accounts %}
{% assign py_accounts = period.minus_1y.accounts %}

{% stripnewlines %}
|
| {{period.year_end_date}}
| {{period.minus_1y.year_end_date}}
{% newline %}
|----80%----
|----10%—:
|----10%—:
{% if accounts[“4000.123”]!=0 and py_accounts[“4000.123”]!=0 %}
{% newline %}
| Test Account 1
| {{accounts[“4000.123”]}}
| {{py_accounts[“4000.123”]}}
{% else %}{% endif %}
{% if accounts[“1”]!=0 and py_accounts[“1”]!=0 %}
{% newline %}
| Test Account 2
| {{accounts[“1”]}}
| {{py_accounts[“1”]}}
{% else %}
{% endif %}
{% endstripnewlines %}

I wrote the above code as a test to see if it was possible to hide a row in which both the current year and prior year values were 0, and this is the result I got (failure :frowning: )

Any ideas on how to solve this problem? I was thinking potentially using a forloop with arrays to populate rows and an if statement saying 'if account!=0 then show row else don’t show row endif within the forloop – but that is essentially the same code as above. What I would need is a way to reference a column. In forloop, you can use forloop.index to reference a row, but I am unsure how to reference a column.

Since CY value is in column #2 and PY value is in column #3, something like ‘if forloop.columnindex !=0 and forloop.columnindex1!=0 then show else don’t show endif’.

I know this code doesn’t exist but if that was understandable, is there some existing logic that can be used to achieve my goal?

Thank you - Spencer

Hi @Spencer.Posner,

You can create a forloop based on an input account collection. This would only show the accounts selected with values in at least one of the columns:

{% input custom.selection.accounts as:account_collection range:"1" accounts_var:accounts %}

{% stripnewlines %}
{% newline %}
|
| {{period.year_end_date}}
| {{period.minus_1y.year_end_date}}
{% newline %}
|----50%----
|----25%----
|----25%-------:+
{% newline %}
{% for account in accounts %}
{% assign prev_year_value = period.minus_1y.accounts |range:account.number %}
| {{ account.number }} {{ account.name }}
| {{ account.value | currency }}
|{{prev_year_value | currency}}
{% newline %}

{% endfor %}
{% endstripnewlines %}

Let me know if that works.

Best,
Borja

@borjaGonzalez

Yes I am aware of this functionality, and it does work. However, I am more concerned with having a specific account referenced, and when it is 0 it doesn’t show, and if it has value it does show. This way I would not have to play guess and check when pulling in accounts, and could just have all accounts in a table with no manual intervention year to year. When there is value show line, when there is not don’t show.

Thank you though!

Hi @Spencer.Posner,

I see what you mean. To test a specific account you could do this:

{% stripnewlines %}
{% newline %}
|
| {{period.year_end_date}}
| {{period.minus_1y.year_end_date}}
{% newline %}
|----50%----
|----25%----
|----25%-------:+
{% newline %}
{% unless period.accounts.102080 == 0 and period.minus_1y.accounts.102080 == 0 %}
| account 1
| {{period.accounts.102080 | currency}}
|{{period.minus_1y.accounts.102080 | currency}}
{% newline %}
{% endunless %}
{% endstripnewlines %}

Let me know if that solves the issue.

Best,
Borja

Yes this works, thank you so much!