# Problems with conditional filtering

**URL:** <https://community.weweb.io/t/problems-with-conditional-filtering/1523>\
**Category:** Ask us anything\
**Tags:** filter\
**Created:** [November 30, 2022, 7:51pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523 "2022-11-30T19:51:11Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [November 30, 2022, 7:51pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523/1 "2022-11-30T19:51:11Z")

</div>

I have a main collection list for which I have a lot of conditional filtering against. I’m having several problems using the ‘filter’ function for a collection list.

I’ve written it out in pseudo-code to keep myself organized. My intended filters:

1. Where if( length (selectFilter) \> 1) apply:
  - collection id IS IN selectFilter
    - Note: could also ‘ignore if empty’ instead of length\>1

2. And if ( viewFavorited) apply:
  - blockID IS IN favoritedBlocks

3. And if ( length(utilitySelect)\>1 apply:
  - rollup (Utility\_id, ‘id’) IS IN utilitySelect
    - Note: could also ignore if empty instead of length\>1

4. And if ( filterOfficial = ‘official’) apply:
  - finalDispo ≠ null
  - OR finalDispo = ‘Approve - Creator’
  - OR finalDispo = ‘Approve - Community’

5. And if ( filterOfficial = ‘communityOffered’) apply:
  - finalDispo = ‘Endorse - Creator’

_ **Currently I have the following problems:** _

- The AND condition group is always applying even when the conditional as to when to apply it is returning false. So I am unable to test the filters after adding a second condition group.
- The same goes for if I have the ‘Ignore if empty’ toggled on. An empty array, or an empty object does not prevent the condition from applying.
- In #3, my fields is an array of objects. I want to filter based on the ‘id’ of the object and if it’s in an array of integers. I am not able to rollup or flatten the field I want to filter by. I am a little stuck on how to filter by the contents of this column.

I have tested most of the filters individually, but I cannot get them to work together in AND. OR works fine.  
Thank you!

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [December 1, 2022, 3:49pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523/2 "2022-12-01T15:49:11Z")

</div>

Can you share also a picture of the editor with your current implementation?

---

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [December 1, 2022, 6:34pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523/3 "2022-12-01T18:34:51Z")

</div>

Sure. Here are the formulas in top to bottom order of the binded values.

 ![Screenshot 2022-12-01 at 10.29.38 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/8/89452c6759fee3d171c6843c287307f9a18e1ed5.png)

 ![Screenshot 2022-12-01 at 10.29.45 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/d/dfdcd5af1178313f86532fc0cf49212d18a5d36b.png)

 ![Screenshot 2022-12-01 at 10.29.51 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/9/9b28ffb4ed9bdc525cfe59783bf74f3619f7a215.png)

 ![Screenshot 2022-12-01 at 10.27.36 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/4/4d65fc964fc510d2d9d2e4f9a691dffe3b0aa041.png)

---

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [December 1, 2022, 6:39pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523/4 "2022-12-01T18:39:59Z")

</div>

I think I just resolved it. The initial condition I think was holding me up. I didn’t realize but it will dictate the entire filter.

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [December 1, 2022, 6:43pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523/5 "2022-12-01T18:43:34Z")

</div>

> [@RCS](#):
>
> I think I just resolved it.

Well done! 🙂

---

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [December 1, 2022, 6:55pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523/6 "2022-12-01T18:55:15Z")

</div>

I am still having problems with this issue though. I’m a bit stuck as to how to only use the rollup of the id of the objects in this array, if I still need to have the add-ons of the entire object from xano.

> [@RCS](#):
>
> In #3, my fields is an array of objects. I want to filter based on the ‘id’ of the object and if it’s in an array of integers. I am not able to rollup or flatten the field I want to filter by. I am a little stuck on how to filter by the contents of this column.

 ![Screenshot 2022-12-01 at 10.49.37 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/b/b8276151013fb5b6697f6d8c2b3588eb513ebb95.png)  
 ![Screenshot 2022-12-01 at 10.53.30 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/5/5ded7a69415103217ce13f92cc9d672e7faee901.png)

---

<div class="post-metadata">

**Author:** ![dorilama](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/dorilama/32/10403_2.png) [@dorilama](https://community.weweb.io/u/dorilama)\
**Post date:** [December 1, 2022, 7:22pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523/7 "2022-12-01T19:22:55Z")

</div>

So your data has a property “utility\_options\_id” that is an array of objects with a property “id”, something like:

```auto
[
	{ "utility_options_id": [{ "id": 0 }, { "id": 1 }] },
	{ "utility_options_id": [{ "id": 2 }, { "id": 3 }] },
	{ "utility_options_id": [{ "id": 0 }, { "id": 4 }] }
]

```

and you want to filter depending on what ids are in the “utility\_options\_id” array.

One option is to modify the data in your backend in a way that they are manageable for your task:

```auto
[
	{
		"utility_options_id": [{ "id": 0 }, { "id": 1 }],
		"all_utility_options_ids": [0, 1]
	},
	{
		"utility_options_id": [{ "id": 2 }, { "id": 3 }],
		"all_utility_options_ids": [2, 3]
	},
	{
		"utility_options_id": [{ "id": 0 }, { "id": 4 }],
		"all_utility_options_ids": [0, 4]
	}
]

```

Now you can filter using “all\_utility\_options\_ids” that is a simple array of numbers.

---

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [December 1, 2022, 7:35pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523/8 "2022-12-01T19:35:44Z")

</div>

I did post this in xano forum as well. I’m trying to avoid creating a separate column of the same information. The column is originally just an array of integers [2, 3, 12]. But that array is a reference to another table, which is why I extend that array of integers to return the data from the referenced table and why it’s returned as an object instead.

I asked in the xano community if it’s possible to return the original array of integers and the object of data separately within the same API endpoint. No luck so far.

The other option I just thought of, is ‘hardcoding’ it in a sense into the original collection list data. Not as a filter. But I’m still running into a similar issue of rolling up the id.

 ![Screenshot 2022-12-01 at 11.34.43 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/b/be79d374d5221d371e99db4fbedc2a25b3b8a660.png)

---

<div class="post-metadata">

**Author:** ![RCS](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@RCS](https://community.weweb.io/u/RCS)\
**Post date:** [December 2, 2022, 6:14pm UTC](https://community.weweb.io/t/problems-with-conditional-filtering/1523/9 "2022-12-02T18:14:15Z")

</div>

I figured out a solution without duplicating data in my data tables, but in my API endpoint in xano.

There’s a method in xano to create an additional return value on the array:

 ![Screenshot 2022-12-02 at 10.12.38 AM](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/6/6880dc44bf1ba7f6923d19462628475ed5a68bcf.png)
