# Multi filter calculation

**URL:** <https://community.hubspot.com/t/multi-filter-calculation/34165>\
**Category:** CMS Development\
**Tags:** developer\
**Created:** [March 19, 2021, 10:25am UTC](https://community.hubspot.com/t/multi-filter-calculation/34165 "2021-03-19T10:25:03Z")\
**Posts on this page:** 4\
**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:** [March 19, 2021, 10:25am UTC](https://community.hubspot.com/t/multi-filter-calculation/34165/1 "2021-03-19T10:25:03Z")

</div>

I currently have 2 conditions that pulls information from HubDB which displays the amount of a particlar item:

**{% set num\_reserved = table | selectattr (“plot\_status.name”,“equalto”,“Reserved”) | length %}**

**{% set num\_detached = table | selectattr (“house\_type.name”,“equalto”,“Detached”) | length %}**

Total Reserved: **{{ num\_reserved }}** \<!--(eg displays 15) --\>

Total Detached: **{{ num\_detached }}** \<!--(eg displays 5) --\>

Is there a way to add these filters together for example show the number of plots that are Reserved AND Detached:

Total of Detached houses that are also Reserved: **{{ ? }}** \<!--(eg displays 2) --\>

---

<div class="post-metadata">

**Author:** ![dennisedson](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dennisedson/32/28044_2.png) [@dennisedson](https://community.hubspot.com/u/dennisedson)\
**Post date:** [March 22, 2021, 2:15pm UTC](https://community.hubspot.com/t/multi-filter-calculation/34165/2 "2021-03-22T14:15:30Z")

</div>

@ben-duchy

The last two lines confude me.

_Is there a way to add these filters together for example show the number of plots that are Reserved AND Detached:_

This looks like you want to add the two together, so you would have 15 + 5 = 20.

To get that, you could create a third variable and add the others.

**{% set totes = num\_reserved + num\_detached %}**

**{{ totes }}**

But the last line seems like you are expecting 2 returned unless you inadvertently left out a 0 😀

@piersg what do you think?

---

<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:** [March 22, 2021, 2:27pm UTC](https://community.hubspot.com/t/multi-filter-calculation/34165/3 "2021-03-22T14:27:19Z")

</div>

@dennisedson I believe @ben-duchy wants to show properties that are both reserved and detached.

You could do this:

```lia-code-sample
{% for row in hubdb_table_rows([TABLE ID], "plot_status=Reserved&house_type=Detached") %}
 {{row}}
{% endfor %}

```

---

<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:** [March 22, 2021, 2:31pm UTC](https://community.hubspot.com/t/multi-filter-calculation/34165/4 "2021-03-22T14:31:08Z")

</div>

Hi @dennisedson,

My apologies for the confusion. I simply wanted to filter out how many rows met both conditions, for example out of the 5 detached properties, 3 are sold. I wanted to see how many are reserved, but at the same time I don’t want to include any other house types that are reserved.

Using 2 “| selectattr”, I was able to combine the conditions into 1 and therefore calulate how many properties met both criterias:

**{% set total\_reserved\_and\_detached = table | selectattr (“plot\_status.name”,“equalto”,“Reserved”) | selectattr (“house\_type.name”,“equalto”,“Detached”) | length %}**

**{{ total\_reserved\_and\_detached }}** \<!-- answer gave me 2 --\> 😊
