# Percent of total

**URL:** <https://community.silverfin.com/t/percent-of-total/1389>\
**Category:** Templates\
**Created:** [February 17, 2019, 4:57pm UTC](https://community.silverfin.com/t/percent-of-total/1389 "2019-02-17T16:57:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![David\_Clesse](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/david_clesse/32/802_2.png) [@David\_Clesse](https://community.silverfin.com/u/David_Clesse)\
**Post date:** [February 17, 2019, 4:57pm UTC](https://community.silverfin.com/t/percent-of-total/1389/1 "2019-02-17T16:57:29Z")

</div>

Hello,

how is it possible to do the following:

## col1: input col2: %

## {% input %} % of total {% input %} % of total {% input %} % of total {% input %} % of total {% input %} % of total

total

Thank you,  
David

---

<div class="post-metadata">

**Author:** ![robindeclercq](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/robindeclercq/32/472_2.png) [@robindeclercq](https://community.silverfin.com/u/robindeclercq)\
**Post date:** [February 18, 2019, 8:11am UTC](https://community.silverfin.com/t/percent-of-total/1389/2 "2019-02-18T08:11:34Z")

</div>

Hi @David_Clesse,

There are probably different ways to calculate this. Here is one example to get the desired result:

I’m assuming you will use a fori-loop in your table, as such:

> {% stripnewlines %}  
> |—|—+{% fori item in custom.items %}{% newline %}  
> |{% input item.suffix %} |{{ % of total }}  
> {% endfori %}{% newline %}  
> {% endstripnewlines %}

As the variable `total` is a local variable, it is important to calculate this total amount above your table (as local variables cannot be used before they are created - Liquid is always read top down). So in order to calculate the `total`, you should loop over the same collection above the table in your code:

> {% assign total = 0 %}  
> {% for item in custom.items %}  
> {% assign total = total+item.suffix %}  
> {% endfor %}

The output `% of total` in your table can than be replaced by `{{ item.suffix/total | percentage }}`, i.e.:

> |—|—+{% fori item in custom.items %}{% newline %}  
> |{% input item.suffix %} |{{ item.suffix/total | percentage }}  
> {% endfori %}{% newline %}  
> {% endstripnewlines %}

Hope this was what you were looking for?

Good luck finishing your table! If you have any more question, do not hesitate to reach out.

Kind regards,  
Robin

---

<div class="post-metadata">

**Author:** ![David\_Clesse](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/david_clesse/32/802_2.png) [@David\_Clesse](https://community.silverfin.com/u/David_Clesse)\
**Post date:** [February 19, 2019, 10:30am UTC](https://community.silverfin.com/t/percent-of-total/1389/3 "2019-02-19T10:30:50Z")

</div>

Hello Robin,  
first, thank you for you kind answer.  
Actually I’m using a ‘hardcoded’ list of 5 custom input rows, without a loop.  
Is it still possible?  
Thank you,  
David.

---

<div class="post-metadata">

**Author:** ![SamVanEenoo](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/samvaneenoo/32/134_2.png) [@SamVanEenoo](https://community.silverfin.com/u/SamVanEenoo)\
**Post date:** [February 19, 2019, 10:56am UTC](https://community.silverfin.com/t/percent-of-total/1389/4 "2019-02-19T10:56:54Z")

</div>

Hi @David_Clesse

Somthing like this should do the trick:

> ```
> {% assign total = custom.item1.value+custom.item2.value+custom.item3.value+custom.item4.value+custom.item5.value %}
> 
> {% stripnewlines %}
> | Value | Percentage of total {% newline %}
> |-----:|----: {% newline %}
> | {% input custom.item1.value as:currency %} | {{ (custom.item1.value/total) | percentage }} {% newline %}
> | {% input custom.item2.value as:currency %} | {{ (custom.item2.value/total) | percentage }} {% newline %}
> | {% input custom.item3.value as:currency %} | {{ (custom.item3.value/total) | percentage }} {% newline %}
> | {% input custom.item4.value as:currency %} | {{ (custom.item4.value/total) | percentage }} {% newline %}
> | {% input custom.item5.value as:currency %} | {{ (custom.item5.value/total) | percentage }} {% newline %}
> |^ **{{ total | currency }}** ^|^ **{{ 1 | percentage }}** ^
> {% endstripnewlines %}
> 
> ```

In the tabel you can see 5 different inputs. You should give them an appropriate name. As @robindeclercq already said, the total has to be calculated at the top. So that’s what I am doing as well. In the right colomn, the individual values are divided by the total.

Kind regards  
Sam

---

<div class="post-metadata">

**Author:** ![David\_Clesse](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.silverfin.com/david_clesse/32/802_2.png) [@David\_Clesse](https://community.silverfin.com/u/David_Clesse)\
**Post date:** [February 19, 2019, 11:13am UTC](https://community.silverfin.com/t/percent-of-total/1389/5 "2019-02-19T11:13:55Z")

</div>

Thank you Sam, that’s exactly what I need 🙂
