Please see my coding below, could you please advise why when I select an account, if this account current year is 0, but prior year has a value, the result will be both current year value and prior year value are not print out, seems like the system just skip that account?
Thanks for your question. You actually are halfway there, as I see you are familiar with the include_zeros method.
Now, you created a collection of accounts in additional_items, and that collection will look at all accounts having a value (different than zero) in the current period. So if an account doesn’t have a value different than zero (but it does in previous year/periods), it won’t be taken into your logic and simply won’t show up.
How to fix this? Well, you’ll need to make sure all accounts of current period are taken into consideration, including the ones with a value zero. And you can do that with adding the method include_zeros into your collection:
{% for additional in additional_items.include_zeros %}
...
{% endfor %}
Hope this helps?
PS do note it is better to use the mapped_number variable instead of the number, as that number can be different than you’d expect.
More info here:
I also fine-tuned your code a bit for the value of the account in current period, as you don’t need to create that with a filter on the period.accounts drop.