Filtering data with AND and OR

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?

No you can’t mix both unfortunately.

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!

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

1 Like

Anytime!

1 Like

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.

2 Likes

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:

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

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 :woozy_face:

Saludos!

1 Like

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

1 Like

Awesome! Muchas gracias!!

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

Ok, so this Filtering data with AND and OR - #3 by MaximeBaker is better native solution then.

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!

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.

The results are identical.

But the time to calculate them is not.

JS took 11ms, ITE took 3ms.

1 Like

Nice test!

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

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