# Add HubDB column data

**URL:** <https://community.hubspot.com/t/add-hubdb-column-data/48206>\
**Category:** CMS Development\
**Tags:** hubdb\
**Created:** [December 8, 2021, 5:10pm UTC](https://community.hubspot.com/t/add-hubdb-column-data/48206 "2021-12-08T17:10:12Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [December 8, 2021, 5:10pm UTC](https://community.hubspot.com/t/add-hubdb-column-data/48206/1 "2021-12-08T17:10:12Z")

</div>

Hello, does anyone know how I can add the contents of a column pulled from HubDB?

I have a column called ‘price’ and I want to add up all the rows that are still available for purchase for example:

```lia-code-sample
{% set price = hubdb_table_rows(1234567) %}

{% set total_price = price | rejectattr ("price","equalto",blank) | selectattr ("status","equalto","Available") %}

```

The above is filtering the data as needed, but I just can’t figure out the total value from this filter. For example each item is £10 and 4 are left to be sold. I need the total to show that the total value of items left to sell is £40.

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [December 8, 2021, 6:04pm UTC](https://community.hubspot.com/t/add-hubdb-column-data/48206/2 "2021-12-08T18:04:34Z")

</div>

Hi @ben-duchy ,

Could you help me out here, please show me the result of

`{{total_price|pprint}}`

Just so I know what we are dealing with. If the value of total\_price is an object, you should be able to make a simple calculation. Something like:

`{% set total_value = total_price.price * total_price.quantity %}`

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [December 9, 2021, 9:46am UTC](https://community.hubspot.com/t/add-hubdb-column-data/48206/3 "2021-12-09T09:46:34Z")

</div>

Hi @Teun,

Thanks for your help.

Using the below returns **(SizeLimitingPyList: [])** but I’m not sure what this means.

`{{total_price|pprint}}`

When entering your example calculation (below) shows errors

`{% set total_value = total_price.price * total_price.quantity %}`

![error.jpg](https://d2qpr2jzcazej7.cloudfront.net/original/3X/5/c/5ccc4a33021cbf5318674f2469c27ed5c4a9eed5.jpeg)

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [December 9, 2021, 9:51am UTC](https://community.hubspot.com/t/add-hubdb-column-data/48206/4 "2021-12-09T09:51:12Z")

</div>

@Teun,

My apologies, I don’t think my original post was very clear.

Ignoring my example and just thinking generically for a moment, how would you filter out just that 1 column in order to add up the contents? Would the column need to be set as a number?

---

<div class="post-metadata">

**Author:** ![piersg](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/piersg/32/99782_2.png) [@piersg](https://community.hubspot.com/u/piersg)\
**Post date:** [December 9, 2021, 10:07am UTC](https://community.hubspot.com/t/add-hubdb-column-data/48206/5 "2021-12-09T10:07:32Z")

</div>

Hi @ben-duchy (and @Teun) just going to add my two pence here. It looks like ‘total\_price’ is a list of rows from your HubDB, so you need to loop over them and add the value of the price column to a variable set outside of said loop. Something like this:

```lia-code-sample
{% set price = hubdb_table_rows(1234567) %}
{% set price_rows = price | rejectattr ("price","equalto",blank) | selectattr ("status","equalto","Available") %}
{% set totalPrice = {'value': 0} %}
{% for row in price_rows %}
 {# using cut and int here to make sure the value is just an integer #}
 {% do totalPrice.update({'value': totalPrice.value + row.price|cut('£')|int}) %}
{% endfor %}
<p>Total value: £{{totalPrice.value}}</p>

```

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [December 9, 2021, 10:27am UTC](https://community.hubspot.com/t/add-hubdb-column-data/48206/6 "2021-12-09T10:27:12Z")

</div>

Hi @ben-duchy ,  
This should be the correct answer. I misread and thought you were retrieving a single row.

---

<div class="post-metadata">

**Author:** ![ben-duchy](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/ben-duchy/32/84083_2.png) [@ben-duchy](https://community.hubspot.com/u/ben-duchy)\
**Post date:** [December 9, 2021, 11:29am UTC](https://community.hubspot.com/t/add-hubdb-column-data/48206/7 "2021-12-09T11:29:37Z")

</div>

That’s perfect, thanks @piersg

(…and @Teun for your help)
