# Filtering data with AND and OR

**URL:** https://community.glideapps.com/t/filtering-data-with-and-and-or/78503
**Category:** Ask for Help
**Created:** [December 10, 2024, 8:43pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503 "2024-12-10T20:43:22Z")
**Posts on this page:** 15
**Page:** 1

<div class="post-metadata">

### Author: ![mbraunperu](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mbraunperu/32/83676_2.png) [@mbraunperu](https://community.glideapps.com/u/mbraunperu)
#### Post date: [December 10, 2024, 8:43pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/1 "2024-12-10T20:43:23Z")

</div>

Hello Gliders! My component is COLLECTION and in OPTIONS I would like to filter like this:

1)TYPE is EXPENSE  
AND  
2) UserID is RowID OR UserID is EMPTY

But apparently you can only use AND or OR throughout. Can´t you mix AND and OR?

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [December 10, 2024, 9:42pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/2 "2024-12-10T21:42:32Z")

</div>

No you can’t mix both unfortunately.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [December 10, 2024, 9:45pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/3 "2024-12-10T21:45:21Z")

</div>

But, as a workaround, you can make multiple if else then else columns with specifics conditions, negation conditions to make it possible to use only AND or only OR. That is what I usually do!

---

<div class="post-metadata">

### Author: ![mbraunperu](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mbraunperu/32/83676_2.png) [@mbraunperu](https://community.glideapps.com/u/mbraunperu)
#### Post date: [December 10, 2024, 10:11pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/4 "2024-12-10T22:11:09Z")

</div>

Yes! The if-then-else column solves the issue. Thanks!

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [December 10, 2024, 10:18pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/5 "2024-12-10T22:18:58Z")

</div>

Anytime!

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [December 11, 2024, 12:06am UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/6 "2024-12-11T00:06:55Z")

</div>

Your If-Then-Else would look like this I believe.

If TYPE is not EXPENSE then false.

If UserID is EMPTY then true.

Is UserID is not RowID then false.

Else true.

---

<div class="post-metadata">

### Author: ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)
#### Post date: [December 11, 2024, 1:51pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/7 "2024-12-11T13:51:36Z")

</div>

Hola Martín,

When this case gets complicated due to new conditionals appearing, I prefer to use this short JS code to handle the logic and use the value “true” as a filter parameter in Glide components.  
Something like this:

```auto
 if ((p1 == "EXPENSE") && (p2 == "yourRowID" || p2 == "")) 
     return true

```

 ![image](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/d/f/df791debf7bdabbf0ff9386d85f7d5c8a9625a71.png)

just play with the conditional AND (&&) / OR (||) by putting your cases in the _IF statement_ to create an easy-to-understand logic

An _If-Then-Else_ column using more than 4-5 combinations (with AND/OR mixtures) can drive anyone crazy 🥴

Saludos!

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [December 11, 2024, 2:56pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/8 "2024-12-11T14:56:03Z")

</div>

I didn’t think about that. You are right, this is so much more powerful!

---

<div class="post-metadata">

### Author: ![mbraunperu](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/mbraunperu/32/83676_2.png) [@mbraunperu](https://community.glideapps.com/u/mbraunperu)
#### Post date: [December 11, 2024, 3:42pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/9 "2024-12-11T15:42:29Z")

</div>

Awesome! Muchas gracias!!

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [December 12, 2024, 12:40am UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/10 "2024-12-12T00:40:02Z")

</div>

Please beware of running JavaScript on bigger tables though. If there’s a “native” solution like If-Then-Else, I would prioritize that.

---

<div class="post-metadata">

### Author: ![MaximeBaker](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/maximebaker/32/80877_2.png) [@MaximeBaker](https://community.glideapps.com/u/MaximeBaker)
#### Post date: [December 12, 2024, 2:24am UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/11 "2024-12-12T02:24:50Z")

</div>

Ok, so this [Filtering data with AND and OR - #3 by MaximeBaker](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/3) is better native solution then.

---

<div class="post-metadata">

### Author: ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)
#### Post date: [December 12, 2024, 9:46pm UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/12 "2024-12-12T21:46:23Z")

</div>

Again … all will depend on the size of your table and the amount of columns you have to create to get a simple result when you have many OR/AND as conditionals in an ITE column.

If I have more than 5-6 conditions and a rare mixture of ON/AND, visually is a little complex understand the logic and worse, modify the logic due to a new condition can be a nightmare.

My rule is simple and I think it applies to save a large amount of data when the APP is running:

- if I can get a result using simple a JS code (1 column) instead of using 3-4 columns with native features (or no code solution), I will choose the JS option without fear in proportion 20-1

If my table has 15k rows, why do I need to create other 45k-60k new rows (by 3-4 columns) only to use a native solution?  
It doesn’t make sense to me.

Saludos a todos!

---

<div class="post-metadata">

### Author: ![ThinhDinh](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/thinhdinh/32/49_2.png) [@ThinhDinh](https://community.glideapps.com/u/ThinhDinh)
#### Post date: [December 13, 2024, 1:25am UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/13 "2024-12-13T01:25:33Z")

</div>

From what I gather in performance mode, anything related to time is slow as hell, then JavaScript is next.

I agree that if you have a very complex case, JavaScript might be better for debugging purposes, but in this case it comes out like this for my 1000 rows sample.

 ![CleanShot 2024-12-13 at 08.23.56](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/b/e/be568910bbf369becd16cf590460a97292669751.png)

 ![CleanShot 2024-12-13 at 08.24.48](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/c/eca43fabab7fc151214788b00a3300472cfd3b9e.png)

 ![CleanShot 2024-12-13 at 08.25.04](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/a/6/a6de82eb5687b5503e8613147327a66b70e94ad4.png)

The results are identical.

But the time to calculate them is not.

 ![CleanShot 2024-12-13 at 08.24.20](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/e/9/e967c7ca1944c8ba22339fee8ecb9b527fd46115.png)

 ![CleanShot 2024-12-13 at 08.24.32](https://us1.discourse-cdn.com/flex002/uploads/glideapps/original/3X/3/8/383d3b265d0e627c5e55155182e2ff899637432f.png)

JS took 11ms, ITE took 3ms.

---

<div class="post-metadata">

### Author: ![gvalero](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/gvalero/32/1037_2.png) [@gvalero](https://community.glideapps.com/u/gvalero)
#### Post date: [December 13, 2024, 2:12am UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/14 "2024-12-13T02:12:22Z")

</div>

Nice test!

In the end I’m not going to fight for 8ms… I invite you a coffee! 😉

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/community.glideapps.com/system/32/53398_2.png) [@system](https://community.glideapps.com/u/system)
#### Post date: [December 20, 2024, 2:13am UTC](https://community.glideapps.com/t/filtering-data-with-and-and-or/78503/15 "2024-12-20T02:13:13Z")

</div>

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.
