# selectattr

**URL:** <https://community.hubspot.com/t/selectattr/40134>\
**Category:** CMS Development\
**Tags:** hubdb\
**Created:** [July 1, 2021, 4:15pm UTC](https://community.hubspot.com/t/selectattr/40134 "2021-07-01T16:15:09Z")\
**Posts on this page:** 3\
**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:** [July 1, 2021, 4:15pm UTC](https://community.hubspot.com/t/selectattr/40134/1 "2021-07-01T16:15:09Z")

</div>

I’m creating a filter that needs to cover an ‘or’ option, but I can’t get it to work beyond the first option. Any ideas what I’m doing wrong?

```lia-code-sample
{% set table = hubdb_table_rows(xxxxxxx, queryparam) %}

{% set performance = table | selectattr ("plot_status.name","equalto","Exchanged") or ("plot_status.name","equalto","Completed")

{% for row in performance %}
 /* Only seems to display plots that are 'Exchanged' */
{% endfor %}

```

---

<div class="post-metadata">

**Author:** ![alyssamwilie](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/alyssamwilie/32/2072_2.png) [@alyssamwilie](https://community.hubspot.com/u/alyssamwilie)\
**Post date:** [July 2, 2021, 12:22am UTC](https://community.hubspot.com/t/selectattr/40134/2 "2021-07-02T00:22:08Z")

</div>

I’m don’t think OR is really possibly with selectattr. Instead you’ll want to create variables for each filter and then use |union to combine them (union will deduplicate any common items so if there’s an item in both lists it’ll only show up once in the for loop).

```lia-code-sample
{% set table = hubdb_table_rows(XXXXXX) %}

{% set performance = table|selectattr("plot_status.name","equalto","Exchanged") %}
{% set performance_2 = table|selectattr("plot_status.name","equalto","Completed") %}

{% for row in performance|union(performance_2) %}

{% 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:** [July 2, 2021, 9:40am UTC](https://community.hubspot.com/t/selectattr/40134/3 "2021-07-02T09:40:55Z")

</div>

Hi @alyssamwilie ,

Thats a good trick, thank you. I wasn’t aware of this filter type.

Just to add to this, is it possible to combine even more lists using ‘union’? I tried the below but it only returns 1 & 2

```lia-code-sample
{% set performance_1 = table | selectattr("plot_status.name","equalto","Exchanged") %}
{% set performance_2 = table | selectattr("plot_status.name","equalto","Completed") %}
{% set performance_3 = table | rejectattr("sale_type.name","equalto","Affordable") %}
{% set performance_4 = table | selectattr("forecast_year.name","equalto","20/21") %}
{% set performance_5 = table | selectattr("forecast_year.name","equalto","21/22") %}

{% for row in performance_1|union(performance_2,performance_3,performance_4,performance_5) %}

```

Having tried different combinations, I feel that I’m close, but just can’t figure out the last part 🤔
