# Check if result exists in previous period

**URL:** <https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304>\
**Category:** Templates\
**Created:** [June 8, 2022, 9:34pm UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304 "2022-06-08T21:34:03Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bjorn\_Lindroth](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/bjorn_lindroth/32/1352_2.png) [@Bjorn\_Lindroth](https://community.silverfin.com/u/Bjorn_Lindroth)\
**Post date:** [June 8, 2022, 9:34pm UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304/1 "2022-06-08T21:34:03Z")

</div>

Hi!  
We have a reconciliation that shows values from the current and previous period. The reconciliation is based on a for…loop that runs through all reconciliations and results in an array. As some reconciliations have been changed we sometimes get an error where the result that is pulled does not exist. To avoid this I would like to use something similar to the method explained here: [https://community.silverfin.com/t/case-check-if-another-reconciliation-exists-with-the-exists-method/1827](https://community.silverfin.com/t/case-check-if-another-reconciliation-exists-with-the-exists-method/1827)

I have tried to adapt that example to instead check if a specific result exist but cannot get it to work. Is there a way to achieve this? The code that throws an error is like this:

> {% assign sub\_result\_amount\_ly = period.minus\_1y.reconciliations.[module\_name].results.[result\_name] %}

In this example “module\_name” and “result\_name” are picked up from the arrays. The code works fine in most cases but where there is a result that does not exist we get an error. Is there a way to check if a result from the current or previous period exists that we could use to avoid this error?  
Thanks!  
Björn

---

<div class="post-metadata">

**Author:** ![Michiel](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/michiel/32/2364_2.png) [@Michiel](https://community.silverfin.com/u/Michiel)\
**Post date:** [June 10, 2022, 1:24pm UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304/2 "2022-06-10T13:24:52Z")

</div>

hi @Bjorn_Lindroth ,

Thank you for your question. Can you please specify the error messages you receive? Do you receive this message when the result does not exist or when the reconciliation does not exist (and therefor the result as well).

Kind regards,

Michiel

---

<div class="post-metadata">

**Author:** ![Bjorn\_Lindroth](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/bjorn_lindroth/32/1352_2.png) [@Bjorn\_Lindroth](https://community.silverfin.com/u/Bjorn_Lindroth)\
**Post date:** [June 13, 2022, 7:26am UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304/3 "2022-06-13T07:26:50Z")

</div>

Hi! The error we receive is:

> - Liquid error (line 445): Reconciliation Text was not found assign sub\_result\_amount\_ly = period.minus\_1y.reconciliations.[module\_name].results.[result\_name]
> - Liquid error (line 449): Reconciliation Text was not found assign text\_array\_source\_ly = period.minus\_1y.reconciliations.[module\_name].results.[text\_key\_ly]
> - Liquid error (line 471): Reconciliation Text was not found assign test\_value\_ly = period.minus\_1y.reconciliations.[template\_url].results.[result\_name]
> - Liquid error (line 472): Reconciliation Text was not found assign ly\_value = period.minus\_1y.reconciliations.[template\_url].results.[result\_name]\*1
> - Liquid error (line 855): Reconciliation Text was not found assign allocation\_amount\_ly = period.minus\_1y.reconciliations.avsattning\_periodiseringsfond.results.total\_allocation\_in\_books\*-1

---

<div class="post-metadata">

**Author:** ![Wouter\_Bruynsteen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/wouter_bruynsteen/32/1196_2.png) [@Wouter\_Bruynsteen](https://community.silverfin.com/u/Wouter_Bruynsteen)\
**Post date:** [June 13, 2022, 8:01am UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304/4 "2022-06-13T08:01:38Z")

</div>

Hi @Bjorn_Lindroth

It sounds like the liquid error is related to the reconciliation not existing in that particular period. If a result does not exist, it will simply return as blank but it wouldn’t throw a liquid error.

I think you’ll need to wrap your calls to the reconciliation of the previous period inside an exists? condition to avoid this error:

```auto
{% if period.minus_1y.reconciliations.[module_name].exists? %}
  {% assign sub_result_amount_ly = period.minus_1y.reconciliations.[module_name].results.[result_name] %}
{% endif %}

```

I hope this helps you further!

Kind regards  
Wouter

---

<div class="post-metadata">

**Author:** ![Bjorn\_Lindroth](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/bjorn_lindroth/32/1352_2.png) [@Bjorn\_Lindroth](https://community.silverfin.com/u/Bjorn_Lindroth)\
**Post date:** [June 13, 2022, 8:34am UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304/5 "2022-06-13T08:34:48Z")

</div>

Hi,  
Unfortunately this does not solve the error. I have suspected that the cause is a missing result so I also tried:

```auto
{% if period.minus_1y.reconciliations.[module_name].results.[result_name].exists? %}

```

But the error remains the same.

---

<div class="post-metadata">

**Author:** ![Wouter\_Bruynsteen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/wouter_bruynsteen/32/1196_2.png) [@Wouter\_Bruynsteen](https://community.silverfin.com/u/Wouter_Bruynsteen)\
**Post date:** [June 13, 2022, 8:58am UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304/6 "2022-06-13T08:58:55Z")

</div>

> [@Bjorn\_Lindroth](#):
>
> `period.minus_1y.reconciliations.[module_name].results.[result_name].exists?`

The exists? method used on the value of a result does not exist, if you want to check if the value of a result exists you should check on blanks like this:

```auto
{% if period.minus_1y.reconciliations.[module_name].results.[result_name] != blank %}

```

But the if-statement I shared above with `exists?` used on the ReconciliationDrop should normally be the solution to solve this liquid error or you could use `!= blank` as well. I suspect you might be still calling on a non-existing reconciliation somewhere without covering it with an if-statement.

Can you reproduce this issue in a sample so we can take a look together?

Kind regards  
Wouter

---

<div class="post-metadata">

**Author:** ![Bjorn\_Lindroth](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/bjorn_lindroth/32/1352_2.png) [@Bjorn\_Lindroth](https://community.silverfin.com/u/Bjorn_Lindroth)\
**Post date:** [June 14, 2022, 2:28pm UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304/7 "2022-06-14T14:28:11Z")

</div>

I have done some more testing and a combination of checking with “exists?” and checking if “result != blank” almost does the trick. The code I have is like this:

> {% assign ly\_value\_exists = false %}  
> {% if period.minus\_1y.reconciliations.[module\_name].exists? %}  
> {% if period.minus\_1y.reconciliations.[module\_name].results.[result\_name] != blank %}  
> {% assign ly\_value\_exists = true %}  
> {% endif %}  
> {% endif %}

I the use the variable “ly\_value\_exists” to determine which values to use. With this code I get only one error message:

> Liquid error (line 23): Reconciliation Text was not found if period.minus\_1y.reconciliations.[module\_name].results.[result\_name] != blank

As I test if every reconciliation exists, does this mean that it is the value in one of the results that is causing this? I am not sure how to dig deeper in this so any help is appreciated. When testing I have put the code in a document text for the project if that helps when looking for the cause of the error. Let me know if I should provide the url to the text.

Thanks!  
Björn

---

<div class="post-metadata">

**Author:** ![Wouter\_Bruynsteen](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/wouter_bruynsteen/32/1196_2.png) [@Wouter\_Bruynsteen](https://community.silverfin.com/u/Wouter_Bruynsteen)\
**Post date:** [June 15, 2022, 7:29am UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304/8 "2022-06-15T07:29:07Z")

</div>

I’m also not sure where the error could be occurring without more details of the code and company, but it might help to perform a check to see if the period exists?

```auto
period.minus_1y.exists?

```

Kind regards  
Wouter

---

<div class="post-metadata">

**Author:** ![Bjorn\_Lindroth](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/bjorn_lindroth/32/1352_2.png) [@Bjorn\_Lindroth](https://community.silverfin.com/u/Bjorn_Lindroth)\
**Post date:** [June 15, 2022, 7:50am UTC](https://community.silverfin.com/t/check-if-result-exists-in-previous-period/2304/9 "2022-06-15T07:50:38Z")

</div>

The period exists. The error only shows for this one company right now as far as I am aware and does not affect the calculations so it is not critical to solve right now. We have in some cases had to unlock and recalculate reconciliations in previous periods in order to get everything to work and I suspect that would solve this as well. But as everything else works here I do not want to risk changing amounts for previous periods so I don’t think it is worth the effort to dig further.

With the new tests for period and results the reconciliation works better so unless the error shows up somewhere else I am happy with leaving this as it is. Thanks for your input!  
Regards,  
Björn
