# Add 2 variables

**URL:** <https://community.silverfin.com/t/add-2-variables/1683>\
**Category:** Templates\
**Created:** [February 23, 2020, 1:30pm UTC](https://community.silverfin.com/t/add-2-variables/1683 "2020-02-23T13:30:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lodillen](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lodillen](https://community.silverfin.com/u/lodillen)\
**Post date:** [February 23, 2020, 1:30pm UTC](https://community.silverfin.com/t/add-2-variables/1683/1 "2020-02-23T13:30:49Z")

</div>

Hello,

I need some help adding 2 variables. The variables have the correct value and printing them individually works just fine. But when I try to add them together, it doesn’t want to work anymore. totalcosts keeps giving the wrong value. I tried different things but I think the problem has something to do with the brackets!  
[Schermafbeelding 2020-02-23 om 14.25.16|644x76](https://community.silverfin.com/uploads/short-url/bsy7zxVup4qER9l5Vdfyy0e71K8.png)

 ![Schermafbeelding 2020-02-23 om 14.25.32](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/2X/f/f505218be8deb356840f12ff20b6dcc762e955dd.png)

Thank you in advance

---

<div class="post-metadata">

**Author:** ![KevinDeConinck](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/kevindeconinck/32/1142_2.png) [@KevinDeConinck](https://community.silverfin.com/u/KevinDeConinck)\
**Post date:** [February 25, 2020, 7:09am UTC](https://community.silverfin.com/t/add-2-variables/1683/2 "2020-02-25T07:09:14Z")

</div>

Hi Lodillen

Without testing your code I could notice that you are using a print syntax (within {{ }}) within your logic syntax (within {% %}). This is not necessary when creating a different variable.

May I suggest you alter your code as followed:  
`{% assign totalcosts = extracosts + custom.amortisation.value %}`

Best regards

---

<div class="post-metadata">

**Author:** ![lodillen](https://avatars.discourse-cdn.com/v4/letter/l/ad7895/32.png) [@lodillen](https://community.silverfin.com/u/lodillen)\
**Post date:** [February 25, 2020, 4:44pm UTC](https://community.silverfin.com/t/add-2-variables/1683/3 "2020-02-25T16:44:10Z")

</div>

> [@KevinDeConinck](#):
>
> {% assign totalcosts = extracosts + custom.amortisation.value %}

Thank you for responding!  
I changed my code to the following:  
 ![Schermafbeelding 2020-02-25 om 17.39.10](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/2X/a/ad96a29b6625bb763b1baa04db19230c3a5dacd3.png)

However, it doesn’t seem to work. The result doesn’t print.

 ![Schermafbeelding 2020-02-25 om 17.42.15](https://canada1.discourse-cdn.com/flex030/uploads/getsilverfin/original/2X/2/2ab62199b0e560b30e97fdb9adb015243981b50d.png)

---

<div class="post-metadata">

**Author:** ![KevinDeConinck](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/kevindeconinck/32/1142_2.png) [@KevinDeConinck](https://community.silverfin.com/u/KevinDeConinck)\
**Post date:** [February 26, 2020, 2:10pm UTC](https://community.silverfin.com/t/add-2-variables/1683/4 "2020-02-26T14:10:49Z")

</div>

Hi Lodillen

There should not be a space when calculating with variables or any value in liquid.  
`{% assign totalcosts = extracosts+custom.amortisation.value %}`

But there is still a second issue in your code:  
You custom field ‘custom.amortisation.value’ shows a default value of 15000, but does not actually store that amount. This can be resolved by assigning it to another variable.  
`{% input custom.amortisation.value as:currency default:15000 assign:amortisation %}`

in the variable ‘totalcosts’ you can now call upon the new variable.

Code should look like this:  
`{% stripnewlines %} |--------- |---15%---:+ {% newline %} | Other costs | {% input custom.amortisation.value as:currency default:15000 assign:amortisation %} {% newline %} {% assign extracosts = $1 %} {% assign totalcosts = extracosts+amortisation %} | | {{ totalcosts | currency }} {% endstripnewlines %}`

Best regards  
Kevin
