# Filtering of the price range problem

Hi,
I was looking for a topic that would solve my problem but I didn’t find it.

I am doing a price filter in my project the filter works well when filtering prices below 10 and prices over 50. I don’t know how to do the middle: I need to filter also: price from 10 to 20, from 20 to 30, from 30 to 50.

I have something like this:

[[ (!c1 && !c2 && !c3 && !c4 && !c5) || (c1 && Item.Price < 10) || (c2 && Item.Price > 10) || (c2 && Item.Price < 20) || (c3 && Item.Price > 20 ) || (c3 && Item.Price < 30 ) || (c4 && Item.Price > 30) || (c4 && Item.Price < 50)|| (c5 && Item.Price > 50) ]]

how to change it to make the filter work in this middle sections?

Hi!

The issue is that you are putting ORs where they shouldn’t be. Example:

``````(c2 && Item.Price > 10) || (c2 && Item.Price < 20)
``````

This says:

“checkbox c2 is selected and price is greater than 10 OR checkbox c2 is selected and price is less than 20”

Because of the OR between the two expressions, either of these things can be true, so this expression will be true for any price whatsoever when c2 is checked, because every price is either greater than 10 OR less than 20.

For example, 100 is greater than 10 OR less than 20 because only one of these two tests needs to be true, and >10 is true for 100. Same applies to -100, as <20 is true for -100.

You need to replace this expression and the ones like it with this:

``````(c2 && Item.Price >= 10 && Item.Price < 20)
``````

Which can be written more verbosely as

``````(c2 == true && Item.Price >= 10 && Item.Price < 20)
``````

Which means:

checkbox c2 is checked AND price is greater than/equal to 10 AND price is less than 20.

The whole filter should look like this:

``````[[ (!c1 && !c2 && !c3 && !c4 && !c5) || (c1 && Item.Price < 10) || (c2 && Item.Price >= 10 && Item.Price < 20) || (c3 && Item.Price >= 20 && Item.Price < 30 ) || (c4 && Item.Price >= 30 && Item.Price < 50) || (c5 && Item.Price >= 50) ]]
``````

Sample: morefilters.rp (62.1 KB)

1 Like

Thanks for help, now everything works! Now I understand filters more!

1 Like

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